Last active
September 27, 2023 16:04
-
-
Save abhijeet-talaulikar/4dbc15d44bd67d19da58e2f7fec518c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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