Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Sandy4321/eb1f09ab93eebbac95f3b94d232466b9 to your computer and use it in GitHub Desktop.
Save Sandy4321/eb1f09ab93eebbac95f3b94d232466b9 to your computer and use it in GitHub Desktop.

Revisions

  1. @abhijeet-talaulikar abhijeet-talaulikar created this gist Aug 21, 2023.
    42 changes: 42 additions & 0 deletions mta-credit-card-barchart.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    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
    )