Skip to content

Instantly share code, notes, and snippets.

@jes-moore
Created December 22, 2018 19:22
Show Gist options
  • Save jes-moore/d547a6328e52b384641b8a4c1617cf46 to your computer and use it in GitHub Desktop.
Save jes-moore/d547a6328e52b384641b8a4c1617cf46 to your computer and use it in GitHub Desktop.
def load_expanded_shooting_df():
shot_df = load_shooting_df()
# Load Team Info
team_info = pd.read_csv('data/team_info.csv')
team_info['combined_name'] = team_info.shortName + ' ' + team_info.teamName
team_info.drop(
['franchiseId', 'shortName', 'teamName', 'abbreviation', 'link'],
axis=1,
inplace=True)
# Load Games Dataset
games_df = pd.read_csv('data/game.csv')
games_df.drop(['venue_link', 'venue_time_zone_id'], axis=1, inplace=True)
# Load and Drop Unused Columns
team_info = pd.read_csv('data/team_info.csv')
team_info['combined_name'] = team_info.shortName + ' ' + team_info.teamName
team_info.drop(
['franchiseId', 'shortName', 'teamName', 'abbreviation', 'link'],
axis=1,
inplace=True)
# Create home and away datasets for joining
away_info = team_info.copy()
away_info.columns = ['away_team_id', 'away_team_name']
home_info = team_info.copy()
home_info.columns = ['home_team_id', 'home_team_name']
# Merge Columns
games_df = games_df.merge(away_info)
games_df = games_df.merge(home_info)
shot_df = shot_df.merge(games_df, on='game_id')
# Get unique games
unique_games = shot_df.game_id.unique()
print("Loaded {} Unique Games".format(len(unique_games)))
time.sleep(0.5) # For printing issue in notebooks
return shot_df, unique_games
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment