I have this dataframe:
df = pd.DataFrame({'Player': ['Pele', 'Platini', 'Beckenbauer'],
'Position': ['Forward', 'Midfielder', 'Defender']})
And I have this function I need to apply to the dataframe, creating a new column 'color'.
def color(position):
if position == 'Forward':
color = 'black'
elif position == 'Midfielder':
color = 'white'
elif position == 'Defender':
color = 'red'
return color
I have tried:
df['Color'] = df.apply(color, axis=1)
But I get the error:
ValueError: ('The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().', 'occurred at index 0')
How do I do this?