Get Started

Calculating retention rate

In this exercise, you will calculate the retention rate, or the number of remaining subscribers from the users who converted to your product. This can give you a sense of whether your marketing campaign converted subscribers who were actually interested in the product.

Conversion rate and retention rate function hand-in-hand; you could create a business with a high conversion rate by giving users a free trial, but have a low retention rate once users are charged for your services. This isn't inherently a bad thing, but it is important to provide your business stakeholders with insight into what percentage of users remain subscribers.

The formula for retention rate is:

$$ \frac{\text{Number of people who remain subscribed}}{\text{Total number of people who converted}} $$

This is a part of the course

“Analyzing Marketing Campaigns with pandas”

View Course

Exercise instructions

  • Calculate the number of subscribers using the user_id and converted columns in the marketing DataFrame.
  • Calculate the number of retained subscribers using the boolean columns user_id and is_retained.
  • Calculate the retention rate.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Calculate the number of subscribers
total_subscribers = ____

# Calculate the number of people who remained subscribed
retained = ____

# Calculate the retention rate
retention_rate = ____
print(round(retention_rate*100, 2), "%")

This exercise is part of the course

Analyzing Marketing Campaigns with pandas

BeginnerSkill Level
4.9+
15 reviews

Build up your pandas skills and answer marketing questions by merging, slicing, visualizing, and more!

In this chapter, you will learn about common marketing metrics and how to calculate them using pandas. You will also visualize your results and practice user segmentation.

Exercise 1: Introduction to common marketing metricsExercise 2: Calculating conversion rateExercise 3: Calculating retention rate
Exercise 4: Customer segmentationExercise 5: Comparing language conversion rate (I)Exercise 6: Comparing language conversion rate (II)Exercise 7: Aggregating by dateExercise 8: Plotting campaign results (I)Exercise 9: Visualize conversion rate by languageExercise 10: Creating daily conversion rate DataFrameExercise 11: Setting up our data to visualize daily conversionExercise 12: Visualize daily conversion rateExercise 13: Plotting campaign results (II)Exercise 14: Marketing channels across age groupsExercise 15: Grouping and counting by multiple columnsExercise 16: Analyzing retention rates for the campaign

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free