Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

nlargest of each group

df.groupby('team').apply(lambda x:x.nlargest(3,'points')).reset_index(drop=True)

  team   player  points
0    A    Alice      15
1    A   Carmen      13
2    A    Becky      11
3    B    Greta      29
4    B     Fran      28
5    B     Iris      25
6    C     Lucy      23
7    C    Molly      18
8    C  Ophelia      15
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #nlargest #group
ADD COMMENT
Topic
Name
6+6 =