Skip to content

Instantly share code, notes, and snippets.

@jes-moore
Created December 22, 2018 19:20
Show Gist options
  • Save jes-moore/f9dae3f9e1c705d6f15328a7c6ebd1a3 to your computer and use it in GitHub Desktop.
Save jes-moore/f9dae3f9e1c705d6f15328a7c6ebd1a3 to your computer and use it in GitHub Desktop.
import pandas as pd
from tqdm import tqdm
import time
def load_shooting_df():
# Get Shot on and Against
plays_df = pd.read_csv('data/game_plays.csv')
shooting_df = plays_df.loc[plays_df.event.isin(['Goal', 'Shot']), :]
# Format Shot by and Goalie
shooting_df = shooting_df.assign(shot_by=shooting_df['description'].apply(
lambda x: ' '.join(x.split()[0:2])).values)
shooting_df = shooting_df.assign(goalie=shooting_df['description'].apply(
lambda x: ' '.join(x.split()[-2:])).values)
# X and Y are inverted in the dataset vs our chart
shooting_df = shooting_df.assign(
X=shooting_df['st_y'].apply(lambda x: x * 500 / 85).values)
shooting_df = shooting_df.assign(
Y=shooting_df['st_x'].apply(lambda x: x * 500 / 85).values)
# ignore shots below center ice
shooting_df = shooting_df.loc[shooting_df['Y'] > 0, :]
shooting_df = shooting_df.loc[shooting_df['Y'] < 516.5, :]
return shooting_df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment