Using the EPL Kaggle dataset, I added a Winner column in the end to display names of the match winner using:
epl['Winner'] = epl.apply(lambda x: x['HomeTeam'] if x['FTR'] == 'H' else (x['AwayTeam'] if x['FTR'] == 'A' else 'Draw'), axis=1)
I have another dataframe 'comp' that sums up values of multiple columns using:
comp = (pd.concat([epl.rename(columns={'HomeTeam':'Team','HY':'YellowCards','HF':'Fouls'}), epl.rename(columns={'AwayTeam':'Team','AY':'YellowCards','AF':'Fouls'})]).groupby(['Season','Team'])[['YellowCards','Fouls']].sum().astype(int).reset_index())
I want to find a way to add the value count of each team's wins every season to the comp dataframe. So it should show:
Season Team Shots On Target YellowCards RedCards Fouls Wins
2000-01 Arsenal 540 295 17 32 495 20
2000-01 Aston Villa 349 165 24 43 491 13
2000-01 Bradford 371 174 27 30 517 5
2000-01 Charlton 373 217 24 22 467 14
etc. all the way to 2021-22
EDIT: To set up the dataframe:
df = pd.read_csv('results.csv')
epl=df.dropna().reset_index(drop=True)