# 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]