Created
March 17, 2022 13:57
-
-
Save databyjp/efd0180f59901f7eb0012d2fea96d4cc to your computer and use it in GitHub Desktop.
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
# Build more granular shot bins | |
filt_start = 0 | |
filt_width = 2 | |
filt_inc = 0.25 | |
gdf_list = list() | |
for i in range(1 + int(30 * (1 / filt_inc))): | |
filt_df = shots_df[(shots_df["shotDistance"] >= filt_start) & (shots_df["shotDistance"] < filt_start + filt_width)] | |
gdf = filt_df.groupby("shot_zone").agg({"shot_made": "sum", "period": "count"}) | |
gdf = gdf.reset_index().rename({"period": "shot_atts"}, axis=1) | |
gdf = gdf.assign(team="NBA") | |
gdf = gdf.assign(filt_start=filt_start) | |
gdf = gdf.assign(shot_freq=gdf.shot_atts / len(shots_df)) | |
gdf = gdf.assign(shot_acc=gdf.shot_made / gdf.shot_atts) | |
gdf_list.append(gdf) | |
filt_start += filt_inc | |
gdf = pd.concat(gdf_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment