📱
Real-world scenario
Grace (Nairobi, Safaricom): Which prepaid cohorts are sticking around?

Grace is a business analyst at Safaricom with 4 years in Excel pivots and retention reports. This month, she's got 6,200 prepaid SIM activations spread across 6 months (Sept 2025 to Feb 2026) and 4 regions. Her manager asks: "Which cohort drops off fastest? Did onboarding improve?"

A naive churn report—counting everyone who didn't pay last month—is useless. New cohorts aren't old enough to compare fairly. The answer: group by signup month, track each cohort separately, build a retention pivot, and read it diagonally. In 30 minutes, Grace will see that Nakuru is stickiest, Feb's cohort is 4% better than Sept's, and month 3 is where churn accelerates.

6
Cohorts (months)
4
Regions
3
Plan types
What you'll learn
  • Why cohort analysis is the only fair way to measure retention
  • Build a cohort key by computing months_since_signup
  • Create a retention pivot with pd.pivot_table
  • Read heatmaps: diagonals show cohort paths, rows show cohort behavior
  • Plot retention curves to spot inflection points
  • Slice cohorts by region, plan, or any dimension
  • Calculate month-1 retention as a leading indicator
📁
Sample cohort data included
Download safaricom_cohorts.csv to follow along (6,200 rows, 6 cohorts across Kenya).

Why cohort analysis? Time-aligned customer behavior

Imagine Grace runs a naive churn report in February 2026: "25% of our prepaid users were inactive last month." That number is useless because it mixes six different cohorts. Sept's cohort has been around 6 months and naturally churns more. Feb's cohort is brand new—of course they're stickier. You can't compare apples (Sept at M6) to oranges (Feb at M0).

Cohort analysis fixes this. Group users by signup month, then track what fraction of each cohort stayed active in month 1, month 2, month 3, etc. Now you compare apples to apples: Sept's month-1 retention (78%) vs. Feb's month-1 retention (82%). You see that Safaricom's onboarding improved by 4 percentage points.

Cohort Retention Heatmap: Each row is a signup month, each column is months since signup. Read diagonals to track a single cohort.
Cohort retention heatmap showing 6 cohorts by 6 months since signup
Read the heatmap: Sept's cohort (row 1) started at 100% (M0), dropped to 78% in month 1, then 64%, 52%, 42%, 32%. Feb's cohort (row 6) follows the same shape but is ~4-10% higher at each step, showing Safaricom's improvement.

Building the cohort key: months_since_signup

Every cohort analysis starts with two computed columns: a cohort ID (usually the signup month) and months since signup. Here's the pattern:

Python

If you're using pandas Period objects (which Safaricom's data is), subtract directly and extract the .n attribute for the numeric offset:

Python

Now each row has a cohort (e.g., "2025-09") and a month offset (0, 1, 2, 3, 4, 5). Group by both to count how many subscribers from each cohort are active at each month offset.

The retention pivot: pd.pivot_table

A retention pivot is a crosstab: rows = cohort months, columns = months since signup, values = count (then divide by cohort size to get %).

Python
Why divide by month 0? Month 0 is always 100% by definition (all subscribers who signed up are "retained" on day 1). Dividing by month-0 count gives you the retention % relative to the cohort's starting size.

The result is Safaricom's retention matrix:

Cohort M0 M1 M2 M3 M4 M5
2025-09 100% 78% 64% 52% 42% 32%
2025-10 100% 78% 66% 53% 43% 33%
2025-11 100% 80% 68% 56% 45% 36%
2025-12 100% 80% 70% 57% 47% 37%
2026-01 100% 81% 70% 58% 48% 38%
2026-02 100% 82% 71% 60% 50% 40%

Read this left-to-right: Each row shows one cohort's journey. Read top-to-bottom: You see how onboarding quality improved—Feb (2026-02) starts at 82%, while Sept started at 78%.

Reading the cohort heatmap: Onboarding quality and churn inflection

The heatmap makes two patterns visible instantly:

  1. Rows get lighter going right: Older cohorts (Sept, Oct) are darker (lower retention). Newer cohorts (Jan, Feb) are lighter (higher retention). This shows Safaricom improved onboarding by 4 percentage points between Sept and Feb.
  2. All rows drop fastest M0→M1→M2, then slow down: This is normal—users who churn do so early. After 3 months, the curve flattens. If month 3-5 churn is steep, it signals something wrong (bad product, pricing change). If it's flat, users are sticky.
Grace's finding: Sept's cohort lost 22% of users in month 1 (78% retained), then lost another 14% from M1 to M2 (64% retained). By month 5, 68% are gone. Feb's cohort loses 18% in M1 (82% retained), a 4% improvement—better onboarding or marketing is working.

Retention curves: Spotting inflection points and comparing cohorts

Plot each cohort as a line: x-axis = months since signup, y-axis = retention %. Lines that are higher and flatter are stickier cohorts.

Retention Curves: Each line is one cohort. Newer cohorts (Feb, Jan) sit higher, showing better month-1 retention. All cohorts dip fastest M0→M2, then flatten.
Line chart showing 6 retention curves by months since signup

Notice the inflection point around month 2-3: All curves drop sharply from M0 to M2, then the slope flattens. This is typical for prepaid—early dropoff is normal (price-sensitive users), but by month 3, survivors are more committed and stick around longer.

If you see a curve that's flat across all months, it means users are sticky from day 1. If a curve drops like a cliff after month 3, something external happened (a bad update, price hike, competitor launch).

Slicing by region and plan: Who's stickiest?

A single retention curve hides regional differences. Grace breaks down month-1 retention by Safaricom's 4 regions:

Month-1 Retention by Region: Nakuru is stickiest at 81.6%. Nairobi slightly lagging at 79.5%. Regional differences are small, so product quality is consistent.
Bar chart of month-1 retention by region

To compute this, filter to month 0 and month 1 data, count by region, then divide:

Python

The variation is small (Nakuru 81.6% vs Nairobi 79.5%), so network quality and product experience are consistent across Kenya. If Nairobi were 60%, you'd investigate coverage or support issues there.

You can apply the same slice-and-compare logic to plans (Prepaid Daily vs Monthly), customer segments, or any dimension in your data.

1
Progress: 1 / 3
What does month-0 in a cohort retention table always equal?
A) 100% — all users who signed up are by definition "active" in month 0
B) 78% — Safaricom's average first-month retention
C) The total number of signups that month
D) A rolling 30-day average
Why is naive churn rate (% inactive last month) misleading in multi-month data?
A) It's too easy to calculate
B) It mixes cohorts of different ages — a 6-month-old cohort naturally has more churn than a 1-month-old one
C) It double-counts users from previous months
D) Safaricom doesn't track activation dates
If a cohort's retention curve is flat from M1 to M5 (stays at 50%), what does that signal?
A) The cohort is dying
B) Early churn happens in M0→M1, but survivors beyond M1 are sticky and stay around
C) There's a data entry error
D) Safaricom lost all premium customers
3
/ 3
Perfect! You've mastered cohort analysis.
Africa & India's Best AI Academy
🤖 AI-first 🎓 Placement Assistance

Ready to go further?

Join the Best AI Program: The AI-Era Analyst — 5 months, fully online, with placement assistance. Week 1 is free.

Explore The AI-Era Analyst →