Skip to content

Instantly share code, notes, and snippets.

@abhijeet-talaulikar
Created August 21, 2023 17:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save abhijeet-talaulikar/74229f484393180c4b57eeb7beb9be24 to your computer and use it in GitHub Desktop.
Save abhijeet-talaulikar/74229f484393180c4b57eeb7beb9be24 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