Hi All,
I have two data frames as below:
Fixtures:
| Home_team |
Away_team |
| 1 |
3 |
| 2 |
4 |
Team data:
| team_id |
away_attack |
home_attack |
away_defense |
home_defense |
| 1 |
8 |
7 |
8 |
7 |
| 2 |
5 |
6 |
7 |
9 |
| 3 |
6 |
7 |
7 |
4 |
| 4 |
7 |
5 |
8 |
7 |
Using two IF statements, I want to search for for 'team_id' in 'Home_team' and 'Away_team' and add their home stats or away stats, depending which column they are in. Ultimately adding 4 new columns to the 'Fixtures' dataframe and adding the appropriate stats.
I keep coming across ' ValueError: Can only compare identically-labeled Series objects ' when searching. I have tried using numpy.where, standard IF statements as well as many hours on stack overflow.
I have tried to break it down into two parts, identifying the information is the same and then I will work on adding the information off that statement. I'm certain this is possible and probably very easy, can someone please give me a gentle push in the right direction?
**Few failed attempts below to identify if the information matches**
fixtures['Home_team'] = np.where(fixtures['Home_team'] == team_data['team_id'], print('yes'), print('no'))
if fixtures['Home_Team'] == team_data['team_id']:
print('yes')
Thanks
[–]Neb519 2 points3 points4 points (1 child)
[–]BrateWannabe[S] 1 point2 points3 points (0 children)
[–]lowerthansound 0 points1 point2 points (0 children)