1. Learn
  2. /
  3. Courses
  4. /
  5. Customer Segmentation in Python

Exercise

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'])

Instructions

100 XP
  • 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.