This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get all team totals for all dates | |
temp_df_list = list() | |
for game_date in game_dates: | |
logger.info(f'Getting data for games on {game_date}') | |
temp_boxes = client.team_box_scores(day=game_date.day, month=game_date.month, year=game_date.year) | |
temp_df = pd.DataFrame(temp_boxes) | |
temp_df = temp_df.assign(game_date=str(game_date)) | |
temp_df_list.append(temp_df) | |
# ========== SET UP BOX SCORE DATAFRAME ========== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> travel_cats = ['home', 'travelled', 'rest_cats'] | |
... travel_grp_df = box_df.groupby(travel_cats).sum() | |
... travel_grp_df = travel_grp_df.assign(games=box_df.groupby(travel_cats)['minutes_played'].count()) | |
... travel_grp_df.reset_index(drop=False, inplace=True) | |
... print(travel_grp_df[travel_cats + ['games']]) | |
home travelled rest_cats games | |
0 False False 2+ Days 15 | |
1 False True 0 Days 246 | |
2 False True 1 Days 717 | |
3 False True 2+ Days 252 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TREEMAPS | |
travel_cats = ['home', 'travelled', 'rest_cats'] | |
travel_grp_df = box_df.groupby(travel_cats).sum() | |
travel_grp_df = travel_grp_df.assign(games=box_df.groupby(travel_cats)['minutes_played'].count()) | |
travel_grp_df.reset_index(drop=False, inplace=True) | |
chart_cats = ['home_str', 'travelled_str', 'rest_cats'] | |
home_away = pd.Series(['Home ' * i for i in travel_grp_df.home.values]) + pd.Series(['Away ' * (1-i) for i in travel_grp_df.home.values]) | |
travel_grp_df['home_str'] = home_away | |
travelled = pd.Series(['Travelled ' * i for i in travel_grp_df.travelled.values]) + pd.Series(['Stayed ' * (1-i) for i in travel_grp_df.travelled.values]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> all_teams_df.head() | |
player pl_acc pl_pps min_start min_mid min_end shots_count shots_made shots_freq shots_acc group | |
0 Jahlil Okafor 65.1 132.6 1 0.5 1 3 1 3.7 33.3 NOP | |
1 Jaxson Hayes 77.8 155.6 1 0.5 1 3 2 3.7 66.7 NOP | |
2 Nicolo Melli 36.4 88.6 1 0.5 1 1 1 1.2 100.0 NOP | |
3 Zion Williamson 54.3 111.4 1 0.5 1 2 1 2.5 50.0 NOP | |
4 Frank Jackson 44.7 105.3 1 0.5 1 0 0 0.0 0.0 NOP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def clean_chart_format(fig): | |
import plotly.graph_objects as go | |
fig.update_layout( | |
paper_bgcolor="white", | |
plot_bgcolor="white", | |
annotations=[ | |
go.layout.Annotation( | |
x=0.9, | |
y=1.02, | |
showarrow=False, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import dash | |
import dash_core_components as dcc | |
import dash_html_components as html | |
from dash.dependencies import Input, Output | |
all_teams_df = pd.read_csv('srcdata/shot_dist_compiled_data_2019_20.csv') | |
app = dash.Dash(__name__) | |
server = app.server |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def clean_chart_format(fig): | |
fig.update_layout( | |
paper_bgcolor="white", | |
plot_bgcolor="white", | |
annotations=[ | |
go.layout.Annotation( | |
x=0.9, | |
y=1.02, | |
showarrow=False, | |
text="Twitter: @_jphwang", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> records_df.head() | |
date team conference net_score games wins losses | |
0 2018-10-16 PHILADELPHIA_76ERS Eastern -18 1 0 1 | |
1 2018-10-16 BOSTON_CELTICS Eastern 18 1 1 0 | |
2 2018-10-16 OKLAHOMA_CITY_THUNDER Western -8 1 0 1 | |
3 2018-10-16 GOLDEN_STATE_WARRIORS Western 8 1 1 0 | |
4 2018-10-17 MILWAUKEE_BUCKS Eastern 1 1 1 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Calculate data | |
utc = pytz.UTC | |
filt_sch_data = nba_sch_data[nba_sch_data.datetime > utc.localize(pd.to_datetime(seed_date))] | |
teams_contacted_df.loc[teams_contacted_df.team == seed_tm, 'contacted'] = True | |
teams_contacted_df.loc[teams_contacted_df.team == seed_tm, 'con_from'] = seed_tm | |
teams_contacted_df.loc[teams_contacted_df.team == seed_tm, 'date'] = pd.to_datetime(seed_date).date() | |
teams_contacted_df.loc[teams_contacted_df.team == seed_tm, 'deg_sep'] = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Iterate every row of schedule: | |
for temp_tup in filt_sch_data.itertuples(): | |
home_tm_contacted = teams_contacted_df.loc[teams_contacted_df.team == temp_tup.home_team, 'contacted'] | |
away_tm_contacted = teams_contacted_df.loc[teams_contacted_df.team == temp_tup.away_team, 'contacted'] | |
if home_tm_contacted.values[0] != away_tm_contacted.values[0]: | |
home_away = [temp_tup.home_team, temp_tup.away_team] | |
for i in range(len(home_away)): | |
tm = home_away[i] | |
other_tm = home_away[1-i] |