I have the following example:
away_team_id home_team_id team_id
1 4 1
3 7 3
6 25 25
12 64 12
I want to create a new one called opponent that is the _team_id that is not team_id, here is what it would look like:
away_team_id home_team_id team_id opponent
1 4 1 4
3 7 7 3
6 25 25 6
12 64 12 64
Here is what I have tried.
df['opponent'] = [df['away_team_id'] if df['team_id'] == df['home_team_id'] else df['home_team_id'] for team_id in df['team_id]]
Where am I going wrong? Thanks.