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
season_tot_df = season_tot_df.assign( | |
fan_ppg=( | |
(season_tot_df.points+ | |
(season_tot_df.offensive_rebounds+season_tot_df.defensive_rebounds)*1.2+ | |
season_tot_df.assists*1.5+season_tot_df['blocks']*2+season_tot_df.steals*2-season_tot_df.turnovers) | |
/season_tot_df.games_played | |
) | |
) |
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 add_fan_pts(in_df): | |
in_df = in_df.assign( | |
fan_pts=( | |
(in_df.points_scored + | |
(in_df.offensive_rebounds + in_df.defensive_rebounds) * 1.2 + | |
in_df.assists * 1.5 + in_df['blocks'] * 2 + in_df.steals * 2 - in_df.turnovers) | |
) | |
) | |
return in_df |
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
top_pl_df_list = list() | |
temp_slugs = season_tot_df[(season_tot_df.fan_ppg > 30) & (season_tot_df.fan_ppg < 40)].slug.unique() | |
for pl_slug in temp_slugs: | |
temp_df = pd.DataFrame(pl_data_dict[pl_slug]) | |
temp_df = add_fan_pts(temp_df) | |
temp_df = temp_df.assign(player=season_tot_df[season_tot_df.slug == pl_slug]['name'].values[0]) | |
top_pl_df_list.append(temp_df) | |
top_pl_df = pd.concat(top_pl_df_list, axis=0) | |
top_pl_df.reset_index(inplace=True, drop=True) | |
# Box plot |
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
# Find players with highest stdev / avg ratio: | |
pl_pts_list = list() | |
for pl_slug in season_tot_df.slug.values: | |
temp_df = pd.DataFrame(pl_data_dict[pl_slug]) | |
temp_df = add_fan_pts(temp_df) | |
fan_pts_mean = temp_df.fan_pts.mean() | |
fan_pts_std = temp_df.fan_pts.std() | |
temp_dict=dict( | |
player=season_tot_df[season_tot_df.slug == pl_slug]['name'].values[0], | |
fan_pts_mean=round(fan_pts_mean, 3), |
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
temp_df_list = list() | |
temp_slugs = season_tot_df[season_tot_df['name'].isin(['James Harden', 'Chris Paul'])].slug.unique() | |
for pl_slug in temp_slugs: | |
temp_df = pd.DataFrame(pl_data_dict[pl_slug]) | |
temp_df = add_fan_pts(temp_df) | |
temp_df = temp_df.assign(player=season_tot_df[season_tot_df.slug == pl_slug]['name'].values[0]) | |
temp_df_list.append(temp_df) | |
comp_df = pd.concat(temp_df_list, axis=0) | |
comp_df.reset_index(inplace=True, drop=True) |
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
top_pl_df_list = list() | |
temp_slugs = season_tot_df[(season_tot_df.fan_ppg > 35) & (season_tot_df.fan_ppg < 40)].slug.unique() | |
for pl_slug in temp_slugs: | |
temp_df = pd.DataFrame(pl_data_dict[pl_slug]) | |
temp_df = add_fan_pts(temp_df) | |
temp_df = temp_df.assign(player=season_tot_df[season_tot_df.slug == pl_slug]['name'].values[0]) | |
top_pl_df_list.append(temp_df) | |
top_pl_df = pd.concat(top_pl_df_list, axis=0) | |
top_pl_df.reset_index(inplace=True, drop=True) | |
# Box plot |
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 ARENA LOCATIONS ========== | |
arena_csv = 'srcdata/arenas_list.csv' | |
arena_df = pd.read_csv(arena_csv) | |
arena_df = arena_df.assign(full_loc=arena_df.arena_name + ', ' + arena_df.arena_city) | |
def get_loc_resp(srch_str): | |
import time | |
import requests |
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
# ========== ADD CAPACITY & AGE ========== | |
from datetime import datetime | |
cur_yr = datetime.today().year | |
arena_df = arena_df.assign(age=(cur_yr-arena_df.opened)) | |
arena_df = arena_df.assign(capacity=arena_df.capacity.str.replace(',','').astype(int)) | |
fig = px.scatter_mapbox( | |
arena_df, lat="lat", lon="lon", zoom=3, size='capacity', color='age', size_max=15, hover_name='teamname') | |
fig.update_layout(mapbox_style="light", mapbox_accesstoken=mapbox_key) # <== Using Mapbox | |
fig.show() |
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 TEAMS' TRAVEL DATA ========== | |
# Load teams' schedules | |
schedule_df = pd.read_csv('srcdata/2020_nba_schedule.csv', index_col=0) | |
arena_df = arena_df.assign(teamupper=arena_df.teamname.str.replace(' ', '_').str.upper()) | |
def get_home_arena(teamname): | |
rows = arena_df[arena_df.teamupper == teamname] | |
return rows |
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
# ========== ANIMATE TRAVEL PATHS ========== | |
# FOR ONE TEAM | |
teamname = 'DALLAS_MAVERICKS' | |
travel_team_df = travel_df[travel_df.teamname == teamname] | |
team_col = teamcolor_dict[teamname] | |
lon_vals = np.append(travel_team_df['orig_lon'].values, travel_team_df['dest_lon'].values[-1]) | |
lat_vals = np.append(travel_team_df['orig_lat'].values, travel_team_df['dest_lat'].values[-1]) | |
frames = list() |
OlderNewer