Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get Maximum points scored by which player in each year?

I have a Data set like this –

Name    Point Year

Player1 498.0 2010

Player2 454.0 2010

Player1 396.0 2011

Player3 214.0 2011

player2 163.0 2011

Now I want to see which Player scored the maximum point in each year.

I tried this –

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Maximum_score = df.groupby(['Year'])['Point'].max()

and got the result –

Year

2010   498.0

2011   396.0

But I want player Name too. How to do this?

>Solution :

You can use boolean indexing. groupby on Year to find maximum points (like you already did) + transform max values for each group for every player in each group, and filter for the players who scored the maximum points for each group:

out = df[df.groupby(['Year'])['Point'].transform('max') == df['Point']]

Output:

      Name  Point  Year
0  Player1  498.0  2010
2  Player1  396.0  2011
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading