Skip to content

Instantly share code, notes, and snippets.

@karamanbk
Created August 23, 2019 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save karamanbk/b9f19d284270ebf7c06aac358aeb6331 to your computer and use it in GitHub Desktop.
Save karamanbk/b9f19d284270ebf7c06aac358aeb6331 to your computer and use it in GitHub Desktop.
#create hv segment
df_hv = pd.DataFrame()
df_hv['customer_id'] = np.array([count for count in range(30000)])
df_hv['segment'] = np.array(['high-value' for _ in range(30000)])
df_hv['group'] = 'A'
df_hv.loc[df_hv.index>=10000,'group'] = 'B'
df_hv.loc[df_hv.index>=20000,'group'] = 'C'
df_hv.loc[df_hv.group == 'A', 'purchase_count'] = np.random.poisson(0.4, 10000)
df_hv.loc[df_hv.group == 'B', 'purchase_count'] = np.random.poisson(0.6, 10000)
df_hv.loc[df_hv.group == 'C', 'purchase_count'] = np.random.poisson(0.2, 10000)
a_stats = df_hv[df_hv.group=='A'].purchase_count
b_stats = df_hv[df_hv.group=='B'].purchase_count
c_stats = df_hv[df_hv.group=='C'].purchase_count
hist_data = [a_stats, b_stats, c_stats]
group_labels = ['A', 'B','C']
# Create distplot with curve_type set to 'normal'
fig = ff.create_distplot(hist_data, group_labels, bin_size=.5,
curve_type='normal',show_rug=False)
fig.layout = go.Layout(
title='Test vs Control Stats',
plot_bgcolor = 'rgb(243,243,243)',
paper_bgcolor = 'rgb(243,243,243)',
)
# Plot!
pyoff.iplot(fig)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment