LoslegenKostenlos loslegen

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

Diese Übung ist Teil des Kurses

Customer Segmentation in Python

Kurs anzeigen

Anleitung zur Übung

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

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# 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 bearbeiten und ausführen