Build a cohort retention table in pandas
8 steps · about 1 h 25 min · Intermediate
- Understand what a cohort analysis answers (article, Wikipedia, 10 min)
Explains grouping users by a shared start event to compare behaviour over time.
- Define retention before you measure it (article, Wikipedia, 10 min)
Clarifies what counts as a retained customer and common retention measures.
- See how product teams read cohort charts (article, Amplitude, 15 min)
Shows acquisition vs behavioural cohorts and how to read a retention curve.
- Download a real transaction dataset (reference, UCI Machine Learning Repository, 5 min)
A year of real online-retail invoices to practise on.
- Turn order dates into monthly periods (reference, pandas, 10 min)
Converts timestamps to months so you can find each customer's cohort.
- Count active customers per cohort and month (reference, pandas, 15 min)
Groups by cohort and period offset to build the raw counts.
- Convert counts to retention rates (reference, pandas, 10 min)
Divides each row by its cohort size along the right axis.
- Shade the retention matrix for reading (reference, pandas, 10 min)
Turns the table into a heatmap so drop-off patterns stand out.