Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas sort values group by

df.groupby(['job']).apply(lambda x: (x.groupby('source')
                                      .sum()
                                      .sort_values('count', ascending=False))
                                     .head(3))
Comment

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
Comment

Group based sort pandas

df_scored.sort_values('Score', ascending= False).sort_index(level='Index1', sort_remaining=False)
Comment

pandas sort values in groupby

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
Comment

PREVIOUS NEXT
Code Example
Python :: python verify if string is a integer 
Python :: Python - How To Count Occurrences of a Character in a String 
Python :: python .findall 
Python :: python enum to int 
Python :: raspi setup gpio 
Python :: absolute url 
Python :: tuple index in python 
Python :: calculer un temps en python 
Python :: pandas write csv 
Python :: dataframe check for nan in iterrows 
Python :: check django version windows 
Python :: regex find email address in string python 
Python :: restrict ticks to integers matplotlib 
Python :: pandas df describe() 
Python :: python generate string 
Python :: python input list of ints 
Python :: matplotlib savefig cutting off graph 
Python :: purpose of meta class in django 
Python :: django sign up 
Python :: serializer phonenumber field json 
Python :: python program to find second largest number in a list 
Python :: python check if number in string 
Python :: pandas read csv dtype list 
Python :: flat numpy array 
Python :: array creation method in numpy 
Python :: how to find a prime number 
Python :: python print every n loops 
Python :: how to join tables in python 
Python :: class indexing 
Python :: print list in one line python 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =