Skip to content

Instantly share code, notes, and snippets.

@lmiller1990
Created August 23, 2018 14:06
Show Gist options
  • Save lmiller1990/4a0a7b714f3394fdde5cbc09d2eecebd to your computer and use it in GitHub Desktop.
Save lmiller1990/4a0a7b714f3394fdde5cbc09d2eecebd to your computer and use it in GitHub Desktop.
def opponent_games(df, team, gameids):
"""
Returns opponents for a given team.
Arguments:
df: the dataframe containing the data.
team: the team you are interested in.
games: a array of gameids the team played in.
"""
games = df[df.gameid.isin(gameids)]
opponent_games = games[games.team != team].drop_duplicates(subset=['gameid'])[['gameid', 'team']]
opponent_games.columns = ['gameid', 'opponent']
return opponent_games
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment