Forked from abhijeet-talaulikar/mta-credit-card-journeys.py
Created
September 27, 2023 16:04
-
-
Save Sandy4321/5a935282d4dd0515f2fb714cbc40f011 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