Analyzing Marketing Campaigns with pandas
Jill Rosok
Data Scientist
# Subset to include only House Ads house_ads = marketing\ [marketing['subscribing_channel'] == 'House Ads']
retained = house_ads[house_ads['is_retained'] == True]\ ['user_id'].nunique() subscribers = house_ads[house_ads['converted'] == True]\ ['user_id'].nunique() retention_rate = retained/subscribers print(round(retention_rate*100,2), '%')
58.05 %
# Group by subscribing_channel and calculate retention
retained = marketing[marketing['is_retained'] == True]\
.groupby(['subscribing_channel'])\
['user_id'].nunique()
print(retained)
subscribing_channel
Email 109
Facebook 152
House Ads 173
Instagram 158
Push 54
Name: user_id, dtype: int64
# Group by subscribing_channel and calculate subscribers
subscribers = marketing[marketing['converted'] == True]\
.groupby(['subscribing_channel'])\
['user_id'].nunique()
print(subscribers)
subscribing_channel
Email 125
Facebook 221
House Ads 298
Instagram 232
Push 77
Name: user_id, dtype: int64
# Calculate the retention rate across the DataFrame
channel_retention_rate = (retained/subscribers)*100
print(channel_retention_rate)
subscribing_channel
Email 87.200000
Facebook 68.778281
House Ads 58.053691
Instagram 68.103448
Push 70.129870
Name: user_id, dtype: float64
Analyzing Marketing Campaigns with pandas