Skip to content

Instantly share code, notes, and snippets.

@abhijeet-talaulikar
Last active September 27, 2023 16:04
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/4dbc15d44bd67d19da58e2f7fec518c8 to your computer and use it in GitHub Desktop.
Save abhijeet-talaulikar/4dbc15d44bd67d19da58e2f7fec518c8 to your computer and use it in GitHub Desktop.
# Step 1: Convert all interactions to a list
journeys = campaign_data.groupby('customer_id')['channel'].aggregate(
lambda x: x.tolist()).reset_index()
# Step 2: Add last interaction as 1 or 0 event representing activation
activation_results = campaign_data.drop_duplicates('customer_id', keep='last')[['customer_id', 'activation']]
journeys = pd.merge(journeys, activation_results, how='left', on='customer_id')
# Step 3: Add start and end states based on whether customer activated
journeys['path'] = np.where(
journeys['activation'] == 0,
journeys['channel'].apply(lambda x: ["Start"] + x + ["Null"]),
journeys['channel'].apply(lambda x: ["Start"] + x + ["Activation"])
)
journeys = journeys[['customer_id', 'path']]
# Get overall activation rate
total_activations = journeys['path'].apply(lambda x: x[-1]).str.match('Activation').sum()
activation_rate = total_activations / journeys.shape[0]
@Sandy4321
Copy link

can you open access to data as mentioned in
Campaign Logs — the goldmine of information
I have created a dataset that resembles what you would typically see in campaign logs.

https://pub.towardsai.net/discrete-time-markov-chains-identifying-winning-customer-journeys-in-a-cashback-campaign-39b62eb8a6fe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment