I have a bunch of rows of data in a pandas DF that contain inconsistently offsetting string characters. For each Game ID (another column), the two string characters are unique to that Game ID, but do not switch off in a predicatble pattern. Regardless, I'm trying to write a helper function that takes each unique game ID and gets the two team names associated with it.
For example...
index game_id
0 400827888
1 400827888
2 400827888
3 400827888
4 400827888
...
555622 400829117
555623 400829117
555624 400829117
555625 400829117
index team
0 ATL
1 DET
2 ATL
3 DET
4 ATL
...
555622 POR
555623 DEN
555624 POR
555625 POR
Here is my woeful attempt, which is not working.
def get_teams(df):
for i in df['gameid']:
both_teams = [df['team'].astype(str)]
return(both_teams)
I'd like it to return ['ATL', 'DET] for Game ID 400827888 and ['POR', 'DEN'] for Game ID 400829117. Instead, it is just returning the team name associated with each index.