Skip to content

Instantly share code, notes, and snippets.

@karamanbk
Created May 3, 2019 20:18
Show Gist options
  • Save karamanbk/f187125f093e199e444a68fa3ad33c45 to your computer and use it in GitHub Desktop.
Save karamanbk/f187125f093e199e444a68fa3ad33c45 to your computer and use it in GitHub Desktop.
#calculate revenue for each customer
tx_uk['Revenue'] = tx_uk['UnitPrice'] * tx_uk['Quantity']
tx_revenue = tx_uk.groupby('CustomerID').Revenue.sum().reset_index()
#merge it with our main dataframe
tx_user = pd.merge(tx_user, tx_revenue, on='CustomerID')
#plot the histogram
plot_data = [
go.Histogram(
x=tx_user.query('Revenue < 10000')['Revenue']
)
]
plot_layout = go.Layout(
title='Monetary Value'
)
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