CommencerCommencer gratuitement

Calculate retention rate from scratch

You have seen how to create retention and average quantity metrics table for the monthly acquisition cohorts. Now it's you time to build the retention metrics by yourself.

The online dataset has been loaded to you with monthly cohorts and cohort index assigned from this lesson. Feel free to print it in the Console.

Also, we have created a loaded a groupby object as grouping DataFrame with this command: grouping = online.groupby(['CohortMonth', 'CohortIndex'])

Cet exercice fait partie du cours

Customer Segmentation in Python

Afficher le cours

Instructions

  • Select the customer ID column, count the number of unique values, store it as cohort_data, and reset its index.
  • Create a pivot with monthly cohort in the index, cohort index in the columns and the customer ID in the values.
  • Select the first column and store it to cohort_sizes.
  • Divide the cohort count by cohort sizes along the rows.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Count the number of unique values per customer ID
cohort_data = grouping[____].apply(pd.Series.____).reset_index()

# Create a pivot 
cohort_counts = cohort_data.____(index=____, columns=____, values=____)

# Select the first column and store it to cohort_sizes
cohort_sizes = cohort_counts.iloc[:,____]

# Divide the cohort count by cohort sizes along the rows
retention = cohort_counts.____(____, axis=____)
Modifier et exécuter le code