Trying to create a new column "Results" based on GF and GA. Wondering how I would do this via defining functions and condition statements. Below is my initial attempt for one row but can't figure out how I would apply to all rows, greatly appreciate your assistance!
| Date | Venue | Opponent | GF | GA |
|---|---|---|---|---|
| 08-19-2017 | H | Crystal Palace | 1 | 0 |
| 08-27-2017 | H | Arsenal FC | 4 | 0 |
| 09-16-2017 | H | Burnley FC | 1 | 1 |
| 10-14-2017 | H | Manchester United | 0 | 0 |
| 10-28-2017 | H | Huddersfield Town | 3 | 0 |
Raw input:
df = pd.DataFrame({'Date': ['08-19-2017', '08-27-2017', '09-16-2017', '10-14-2017', '10-28-2017'],
'Venue': ['H', 'H', 'H', 'H', 'H'],
'Opponent': ['Crystal Palace', 'Arsenal FC', 'Burnley FC', 'Manchester United', 'Huddersfield Town'],
'GF': [1, 4, 1, 0, 3],
'GA': [0, 0, 1, 0, 0]})
My attempt:
# for one row (match)
gf = df[0, 3]
ga = df[0, 4]
if gf > ga:
print('W')
elif gf < ga:
print('L')
else:
print('D')
output: W
Would to apply this to all rows, how would I go about a solution based on:
```# create a function
def win_draw_loss():
if df['GF'] > df['GA']:
print('W')
elif mo_rec['GF'].sum() < mo_rec['GA'].sum():
print('L')
else:
print('D')
# making the new pandas column
df['results'] = ```