Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

groupby and sort python

In[34]: df.sort_values(['job','count'],ascending=False).groupby('job').head(3)

Out[35]: 
   count     job source
4      7   sales      E
2      6   sales      C
1      4   sales      B
5      5  market      A
8      4  market      D
6      3  market      B
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #groupby #sort #python
ADD COMMENT
Topic
Name
3+3 =