I am looking to create a new column in a data frame that indicates if the game ended in a home victory, away victory or a draw.
this is the code i am currently using:
for value in df2:
if value in df2['home_goals'] > df2['away_goals']:
df2['result'] = 'H'
elif value in df2['home_goals'] < df2['away_goals']:
df2['result'] = 'A'
else:
df2['result'] = 'D'
This is the output.
Home Team Away Team home_goals away_goals result
Season
2018-2019 Man Utd Leicester 2 1 D
2018-2019 Newcastle Spurs 1 2 D
2018-2019 Bournemouth Cardiff 2 0 D
2018-2019 Fulham Crystal Palace 0 2 D
2018-2019 Huddersfield Chelsea 0 3 D
As you can see rather showing that the Home team or away team has won in that scenario it is showing all of the results as draws.
Can someone please enlighten me in where I have gone wrong?
Thanks
