i’m trying to get the maximum games wins and losses played for each team

Grouping your DataFrame can get the job done for you. I’ll demonstrate using this simplified version of your data:

import pandas as pd

data = {
        'Team':['L.A. Lakers', 'Denver', 
                'Houston', 'Utah', 'Oklahoma', 
                'L.A. Lakers', 'Dallas'],
        'G':[59,60,59,59,60,58,60],
        'W':[46,41,39,37,37,45,36],
        'L':[13,19,20,22,23,13,24],
        }

df = pd.DataFrame(data)
print(df)

Out:

          Team   G   W   L
0  L.A. Lakers  59  46  13
1       Denver  60  41  19
2      Houston  59  39  20
3         Utah  59  37  22
4     Oklahoma  60  37  23
5  L.A. Lakers  58  45  13
6       Dallas  60  36  24

Now I can use groupby and aggregate by max values:

grouped = df.groupby('Team')[['G', 'W', 'L']].agg('max')
print(grouped)

Out:

              G   W   L
Team                   
Dallas       60  36  24
Denver       60  41  19
Houston      59  39  20
L.A. Lakers  59  46  13
Oklahoma     60  37  23
Utah         59  37  22

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top