Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sandy4321/eb1f09ab93eebbac95f3b94d232466b9 to your computer and use it in GitHub Desktop.
Save Sandy4321/eb1f09ab93eebbac95f3b94d232466b9 to your computer and use it in GitHub Desktop.
df_multi = pd.DataFrame({
'Channel': attributions.keys(),
'Attribution style': 'Journey',
'Activations': attributions.values()
})
df_first = pd.DataFrame({
'Channel': attributions.keys(),
'Attribution style': 'First touchpoint'
})
df_first['Activations'] = df_first['Channel'].map(
journeys.loc[
journeys.path.apply(lambda x: x[-1]) == 'Activation',
'path'
].apply(lambda x: x[1]).value_counts().to_dict()
)
df_last = pd.DataFrame({
'Channel': attributions.keys(),
'Attribution style': 'Last touchpoint'
})
df_last['Activations'] = df_last['Channel'].map(
journeys.loc[
journeys.path.apply(lambda x: x[-1]) == 'Activation',
'path'
].apply(lambda x: x[-2]).value_counts().to_dict()
)
df_plot = pd.concat([df_multi, df_first, df_last], axis=0)
sns.set_style("darkgrid", {"axes.facecolor": ".9"})
color_codes = ['#2653de','#6989EA','#98AEF0']
sns.catplot(
data=df_plot, kind="bar",
x="Channel", y="Activations", hue="Attribution style",
palette=sns.color_palette(color_codes),
height=6, aspect=12/8
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment