Aan de slagGa gratis aan de slag

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

Deze oefening maakt deel uit van de cursus

Customer Segmentation in Python

Cursus bekijken

Oefeninstructies

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

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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=____)
Code bewerken en uitvoeren