Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created January 8, 2021 07:54
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 amankharwal/832816c0e9fc28e7c1404a8b97f75e73 to your computer and use it in GitHub Desktop.
Save amankharwal/832816c0e9fc28e7c1404a8b97f75e73 to your computer and use it in GitHub Desktop.
#Average quantity for each cohort
grouping = df.groupby(['CohortMonth', 'CohortIndex'])
cohort_data = grouping['Quantity'].mean()
cohort_data = cohort_data.reset_index()
average_quantity = cohort_data.pivot(index='CohortMonth',columns='CohortIndex',values='Quantity')
average_quantity.round(1)
average_quantity.index = average_quantity.index.date
#Build the heatmap
plt.figure(figsize=(15, 8))
plt.title('Average quantity for each cohort')
sns.heatmap(data=average_quantity,annot = True,vmin = 0.0,vmax =20,cmap="BuGn_r")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment