Python
All Top 50 Python & Pandas Interview Questions#49
Calculate Monthly Churn and Retention Cohorts in Pandas
HardGoogleInterview Question #49
Asked at GoogleGiven `active_users` (user_id, activity_month), write a function to calculate the churn rate percentage for each month.
Input Table: activity
3 rows preview| user_id | month |
|---|---|
| 1 | 2026-01 |
| 2 | 2026-01 |
| 1 | 2026-02 |
Expected Output Structure1 rows
| month | churn_rate_pct |
|---|---|
| 2026-01 | 50 |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
Python 3.10 (Pandas)
Environment Ready
Click "Run & Test" to execute your Pandas code against the test assertions.