You're given a small event log of user activity: each row is one (user, month) pair in which that user was active, along with the month they originally signed up. Build a cohort retention matrix: rows are signup cohort (month), columns are months-since-signup (0, 1, 2, ...), and values are the retention rate — the share of that cohort active in that month.
Steps:
months_since_signup = (active_month − signup_month) in whole months.signup_month equals that cohort).signup_month, columns=months_since_signup, values=retention rate. Months with no data for a cohort should be left as NaN (not zero) — a cohort simply hasn't reached that age yet.Reset the index so signup_month is a normal column, round all rate values to 4 decimals, and assign the DataFrame to result.
Ready to take your skills to the next level? Enroll in our comprehensive Data Analyst Career Track to master SQL, Python, Excel, and Power BI.
Run your code to see the result here.