Created
May 3, 2019 15:02
-
-
Save karamanbk/9207a3a656c2d1e8c88af67c4e19f5c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#create a dataframe that shows new user ratio - we also need to drop NA values (first month new user ratio is 0) | |
tx_user_ratio = tx_uk.query("UserType == 'New'").groupby(['InvoiceYearMonth'])['CustomerID'].nunique()/tx_uk.query("UserType == 'Existing'").groupby(['InvoiceYearMonth'])['CustomerID'].nunique() | |
tx_user_ratio = tx_user_ratio.reset_index() | |
tx_user_ratio = tx_user_ratio.dropna() | |
#print the dafaframe | |
tx_user_ratio | |
#plot the result | |
plot_data = [ | |
go.Bar( | |
x=tx_user_ratio.query("InvoiceYearMonth>201101 and InvoiceYearMonth<201112")['InvoiceYearMonth'], | |
y=tx_user_ratio.query("InvoiceYearMonth>201101 and InvoiceYearMonth<201112")['CustomerID'], | |
) | |
] | |
plot_layout = go.Layout( | |
xaxis={"type": "category"}, | |
title='New Customer Ratio' | |
) | |
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