Build a cohort retention table in pandas

8 steps · about 1 h 25 min · Intermediate

  1. Understand what a cohort analysis answers (article, Wikipedia, 10 min)

    Explains grouping users by a shared start event to compare behaviour over time.

  2. Define retention before you measure it (article, Wikipedia, 10 min)

    Clarifies what counts as a retained customer and common retention measures.

  3. See how product teams read cohort charts (article, Amplitude, 15 min)

    Shows acquisition vs behavioural cohorts and how to read a retention curve.

  4. Download a real transaction dataset (reference, UCI Machine Learning Repository, 5 min)

    A year of real online-retail invoices to practise on.

  5. Turn order dates into monthly periods (reference, pandas, 10 min)

    Converts timestamps to months so you can find each customer's cohort.

  6. Count active customers per cohort and month (reference, pandas, 15 min)

    Groups by cohort and period offset to build the raw counts.

  7. Convert counts to retention rates (reference, pandas, 10 min)

    Divides each row by its cohort size along the right axis.

  8. Shade the retention matrix for reading (reference, pandas, 10 min)

    Turns the table into a heatmap so drop-off patterns stand out.