I have a dataframe with data from many players of different teams. What I wanted was to groupby 'team' and only keep the rows with the max value from height.
When I used this code, I just got the 'Team' label and peoples heights:
Code:
df.groupby(['team'], sort=True)['height'].max()
Output:
team
Argentina 199
Australia 193
Belgium 199 (...)
Then I combined the groupby with loc to get the whole information of the players:
fifa.loc[fifa.groupby('team')['height'].idxmax()]
This printed the whole rows, but I don´t understand why do I use idxmax()
and not max()
at the end of the code.
Can anyone explain me the difference?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.