Context:
- I have a dataframe on football match statistics
- This dataframe is missing info on outcome of the match
- Hence, I am trying to create a column that lets me know if the match outcome is a "Win" or "Lose"
- The dataframe contains goals scored by Home & Away teams
- I am trying to populate a new column with "Win" when Home goals is more than Away goals
- You can see in my code below that the new column I was trying to create is called "outcome"
Below's working code should give a sense of what I am trying to do, and am doing wrong...
for index, row in match_df.iterrows():
if match_df.home_team_goal > match_df.away_team_goal:
match_df.loc[index, "outcome"] = "Win"
else:
match_df.loc[index, "outcome"] = "Lose"
Error Message:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Aucun commentaire:
Enregistrer un commentaire