<jupyter_start><jupyter_text>Load datasets<jupyter_code>start_year = 1984
end_year = 2018
df_season_summaries = pd.read_csv("../Data/nba_season_summaries_{}_{}.csv".format(start_year, end_year), index_col=[0, 1])
# For MultiIndex slicing support
df_season_summaries.sort_index(inplace=True) 
df_boxscores = pd.read_csv("../Data/nba_boxscores_{}_{}.csv".format(start_year, end_year), index_col=0, parse_dates=[1], infer_datetime_format=True)
df_season_summaries.head()
df_boxscores.head()<jupyter_output><empty_output><jupyter_text>Functions for querying/masking<jupyter_code>boxscore_season_range_mask = lambda df, start_year, end_year:  (df["season"] >= start_year) & (df["season"] <= end_year)
boxscore_date_range_mask = lambda df, start_date, end_date: (df["date"] >= start_date) & (df["date"] <= end_date)
boxscore_team_mask = lambda df, team_initials: (df["team1"] == team_initials) | (df["team2"] == team_initials)
boxscore_regular_season_mask = lambda df: pd.isnull(df["playoff"])

summary_season_range = lambda df, start_year, end_year: df.loc[start_year:end_year]
summary_season_query = lambda df, years, teams, col_names: df.loc[(years, teams), col_names]
summary_season_remove_league_average = lambda: df<jupyter_output><empty_output><jupyter_text>Cleaning data for plotting<jupyter_code># Only use completed seasons
df_season_summaries = df_season_summaries.loc[1984:2017]
X = df_season_summaries.columns.values.tolist()
remove_cols = ["Rk", "W", "L", "PW", "PL", "MOV", "SOS", "Arena", "Attend.", "Attend./G"]
X = [x for x in X if x not in remove_cols]
y = "W"
df_season_summaries = df_season_summaries.dropna(subset=X)<jupyter_output><empty_output><jupyter_text>Visualization: Regular season wins vs. season metrics<jupyter_code># Pearson r correlations of wins vs. various season metrics
correlations = [(x, df_season_summaries[[y, x]].corr().loc[x][y]) for x in X]
plt.figure(1, figsize=(16,16), dpi=85)
plt.suptitle("Wins vs season metrics (regular seasons 1984-2017)", fontsize=20)
sqrt_X = np.sqrt(len(X))
rows = int(sqrt_X)
cols = int(len(X) / int(sqrt_X)) + 1
shared_y = plt.subplot(111)
shared_y.set_ylabel("W")
for indx, (x, pearsonR) in enumerate(sorted(correlations, key=lambda t: t[1], reverse=True)):
    ax = plt.subplot(rows, cols, indx+1, sharey=shared_y) 
    ax.set_xlabel(x)
    ax.text(0.025, 0.9, "r={}".format(round(pearsonR, 4)), transform=ax.transAxes)  
    ax.scatter(df_season_summaries[x], df_season_summaries[y], c='b', alpha=0.05)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15335463258785942, 'fraction_numerical': 0.02196485623003195, 'mean_word_length': 7.7894736842105265, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '580793', 'license': 'MIT', 'n_tokens_mistral': 1012, 'n_tokens_neox': 956, 'n_words': 179, 'path': 'Src/data_exploration.ipynb', 'repo_name': 'JKasakyan/nba-win-prob-model', 'size': '2504'}