Skip to content

Instantly share code, notes, and snippets.

@karamanbk
Created May 4, 2019 09:20
Show Gist options
  • Save karamanbk/aa87cbf05cfd69bf823f1f25a1a0b502 to your computer and use it in GitHub Desktop.
Save karamanbk/aa87cbf05cfd69bf823f1f25a1a0b502 to your computer and use it in GitHub Desktop.
#calculate revenue and create a new dataframe for it
tx_6m['Revenue'] = tx_6m['UnitPrice'] * tx_6m['Quantity']
tx_user_6m = tx_6m.groupby('CustomerID')['Revenue'].sum().reset_index()
tx_user_6m.columns = ['CustomerID','m6_Revenue']
#plot LTV histogram
plot_data = [
go.Histogram(
x=tx_user_6m.query('m6_Revenue < 10000')['m6_Revenue']
)
]
plot_layout = go.Layout(
title='6m Revenue'
)
fig = go.Figure(data=plot_data, layout=plot_layout)
pyoff.iplot(fig)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment