Build a Day-N Retention Table for an Android App in Pandas
Last updated: November 29, 2026
Quick Overview
Given signups and daily activity for an Android app, produce a table with weekly signup cohorts as rows and Day-1, Day-7, and Day-30 retention as columns, leaving cells blank where the cohort is too recent to measure.
0
0
0 solved
Given signups and daily activity for an Android app, produce a table with weekly signup cohorts as rows and Day-1, Day-7, and Day-30 retention as columns, leaving cells blank where the cohort is too recent to measure.
Google data scientists frequently prototype metrics in Python notebooks before productionizing them in SQL. The interviewer checks a correct retention definition, cohort assignment, deduplication, and the immature-cohort trap.
What the Interviewer Expects
- Define Day-N retention precisely (active exactly on day N after signup)
- Assign weekly cohorts by signup date
- Deduplicate activity to user-day
- Divide by cohort size including users with no activity
- Mask cohorts that have not reached day N
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you compute rolling (on or after day N) retention instead?
- How would you handle reinstalls with a new user id?
- How would you add confidence intervals for small cohorts?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
signups(user_id, signup_date), one row per user. events(user_id, event_date), possibly many rows per user per day. Day-N retention: fraction of a cohort active on exactly day N, where signup day i...
Approach
Normalize dates, dedupe events, join to signups to get day_n, count distinct active users per cohort for each N, divide by full cohort size, and set the cell to NaN unless the youngest user in the c...