Skip to content

Instantly share code, notes, and snippets.

@databyjp
Created January 14, 2021 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save databyjp/03c76c35a764d6423bffca32772e8acd to your computer and use it in GitHub Desktop.
Save databyjp/03c76c35a764d6423bffca32772e8acd to your computer and use it in GitHub Desktop.
# 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