Skip to content

Instantly share code, notes, and snippets.

@databyjp
Created January 13, 2021 08:39
Show Gist options
  • Save databyjp/3c7870ff8bc74230e5d9fd66d06e9e3a to your computer and use it in GitHub Desktop.
Save databyjp/3c7870ff8bc74230e5d9fd66d06e9e3a to your computer and use it in GitHub Desktop.
# ===== Group dataframe by player & game
players = shots_df.groupby("player").count()["date"].sort_values()[-200:].index
pl_df = shots_df[shots_df.player.isin(players)]
grp_pl_df = pl_df.groupby(["player", "date"]).shot_made.sum().reset_index()
grp_pl_df = grp_pl_df.assign(shot_count=pl_df.groupby(["player", "date"]).shot_made.count().values)
grp_pl_df = grp_pl_df.assign(shot_acc=grp_pl_df["shot_made"]/grp_pl_df["shot_count"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment