Daily Active Users and Share by Platform in Pandas
Last updated: November 29, 2026
Quick Overview
From an app events DataFrame with user_id, platform (ios, android, web) and event timestamp, build a daily table of distinct active users per platform, total distinct DAU, and each platform's share of total DAU.
TikTok
November 29, 20260
0
0 solved
From an app events DataFrame with user_id, platform (ios, android, web) and event timestamp, build a daily table of distinct active users per platform, total distinct DAU, and each platform's share of total DAU.
A quick pandas warm-up in TikTok data science screens, tied to tracking how usage splits between the mobile apps and tiktok.com on desktop. The interviewer checks distinct counting, pivoting, and whether you notice that multi-platform users make shares add up to more than 100%.
What the Interviewer Expects
- Truncate timestamps to dates before counting
- Count distinct users, not events
- Pivot platforms into columns with zero fill
- Compute total DAU independently instead of summing platform columns
- Explain why shares can sum above 1
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 report a mutually exclusive split (iOS only, Android only, multi-platform)?
- How would you make dates follow each user's local timezone?
- How would you extend this to a 7-day rolling view per platform?
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
events(user_id, platform, event_ts), many events per user per day.- DAU means distinct users with any event that day (UTC for this exercise).
- Share of DAU for a platform = users active on that ...
Approach
- Derive
date, drop duplicate(date, user_id, platform)rows to keep the pivot light. pivot_tablewithnuniqueper platform andfill_value=0for days where a platform had nobody.- Tota...