0

I have NBA data for every game played until January of 2023. I went ahead and combined all the points and now have it as this:

I used the groupby function to sum up total PTS

I wanted to filter the dataframe to show the most points scored by a player for a given season. For example:

Season Name Pts
2022 Player 1 2938
2021 Player 2 2111
most_points = nba_data.groupby(by=['Season', 'Name'])[['Pts']].sum()
most_points.sort_values(by='Pts', ascending=False)
FruitBoy
  • 9
  • 2

1 Answers1

0

Using pandas.DataFrame.loc and df.groupby().idxmax() in the below approach will produce your expected output

most_pts = nba_data.loc[nba_data.groupby(['Season'])['Pts'].idxmax()]
print(most_pts) 
Jamiu S.
  • 5,257
  • 5
  • 12
  • 34