Skip to content

Instantly share code, notes, and snippets.

@naenumtou
Created September 28, 2022 13:42
Show Gist options
  • Save naenumtou/a46941ae978fd907f45c448a916bbcb3 to your computer and use it in GitHub Desktop.
Save naenumtou/a46941ae978fd907f45c448a916bbcb3 to your computer and use it in GitHub Desktop.
# Average spending price per period
df['TotalSale'] = df['Price'] * df['Quantity'] #Calculation total sale
dfPrice = df.groupby(
['cohortMonth', 'cohortIndex'],
as_index = False
)['TotalSale'].mean()
dfPrice = pd.pivot_table(
dfPrice,
values = 'TotalSale',
index = ['cohortMonth'],
columns = ['cohortIndex']
) # Pivot
# Plot
plotTable(dfPrice, 'Total spending by month', percent = False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment