Created
January 14, 2021 12:47
-
-
Save databyjp/03c76c35a764d6423bffca32772e8acd to your computer and use it in GitHub Desktop.
This file contains 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 column for cold/neutral/hot start - based on (n_streak-margin) / n_streak makes or misses) | |
shots_df = shots_df.assign(start="Unknown") | |
for pl in players: | |
logger.info(f"Processing data for {pl}") | |
dates = shots_df[shots_df.player == pl].date.unique() | |
for date in dates: | |
day_filter = ((shots_df.player == pl) & (shots_df.date == date)) | |
day_df = shots_df[day_filter].sort_values("tot_time") | |
if len(day_df) > n_streak: | |
if day_df[:n_streak]["shot_made"].sum() >= n_streak - margin: | |
shots_df.loc[day_filter, "start"] = "Hot" | |
elif day_df[:n_streak]["shot_made"].sum() <= margin: | |
shots_df.loc[day_filter, "start"] = "Cold" | |
else: | |
shots_df.loc[day_filter, "start"] = "Neutral" | |
# take a look at players' shot distances AFTER the hot / cold start | |
tmp_df = shots_df[shots_df.start.isin(["Hot", "Cold"])] | |
hot_grp_df = tmp_df[tmp_df.player.isin(players)].groupby(["player", "start"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment