Fill Missing Days in Prime Video Regional Watch Hours
Last updated: November 29, 2026
Quick Overview
You receive a pandas DataFrame of daily Prime Video watch hours per region (date, region, watch_hours), but days with a logging outage or no data are simply absent. Produce a dense daily series per region over a given date range, filling missing days with zero and flagging which rows were filled.
Amazon
November 29, 20260
0
0 solved
You receive a pandas DataFrame of daily Prime Video watch hours per region (date, region, watch_hours), but days with a logging outage or no data are simply absent. Produce a dense daily series per region over a given date range, filling missing days with zero and flagging which rows were filled.
Prime Video analysts build dashboards and forecasts on daily regional engagement, and a missing row looks like a flat line to a chart but breaks rolling windows and lag features. This Easy pandas question checks whether you know reindexing with a MultiIndex and whether you think about the difference between a true zero and missing data.
What the Interviewer Expects
- Aggregate duplicate (region, date) rows before reindexing
- Build the full index with pd.date_range and MultiIndex.from_product
- Reindex and fill, keeping a flag for imputed rows
- Discuss when zero is the wrong fill (outage vs no viewing)
- Keep the output tidy with reset_index
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
- When would you forward-fill or interpolate instead of filling with zero?
- How would you do this with groupby and asfreq instead of a MultiIndex?
- What if a region launched mid-range and should not have rows before launch?
- How would you detect logging outages automatically from this series?
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
- Columns:
date(string or datetime),region,watch_hours. A region-day may appear more than once if upstream partitions overlap, so I will sum duplicates first. - The date range is given explic...
Approach
Build the complete grid of every region crossed with every day using pd.MultiIndex.from_product, then reindex the aggregated data onto that grid. Rows that did not exist come back as NaN, which I ...