Rolling Seven-Day Completed Trips per City With Gaps Filled

Last updated: November 29, 2026

Quick Overview

Given a trips table in pandas, compute daily completed trips per city, a trailing seven-day total and average, and the week-over-week change, making sure days with zero trips are included.

Uber
Data Manipulation (SQL/Python)
Data Scientist
Uber
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Given a trips table in pandas, compute daily completed trips per city, a trailing seven-day total and average, and the week-over-week change, making sure days with zero trips are included.

City-level daily trip trends are a constant view for Uber ops and data science, and rolling windows over sparse daily data are a frequent source of subtle errors. The interviewer checks the zero-fill step and correct grouping in rolling calculations.

What the Interviewer Expects
  • Filter to completed trips and aggregate by city and day
  • Reindex to a full city by day grid so missing days are zero
  • Compute the rolling sum within each city
  • Use min_periods to avoid partial windows
  • Compute week-over-week change on the rolling total
Key Topics to Cover
pandas
rolling windows
reindexing
time series aggregation
groupby transform
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • Why is a time-based rolling window ('7D') different from rolling(7) on unfilled data?
  • How would you flag anomalous days?
  • How would you handle cities launched mid-period?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

trips(trip_id, city, completed_at, status). Report window start to end. Rolling total covers the current day and the six before it. Cities come from the trips table (in production, from a city d...

Approach
  1. Filter completed, normalize timestamps to days, count per (city, day).
  2. Build a MultiIndex of every city crossed with every day, reindex with zeros.
  3. Group by city, rolling 7 with `min_periods=...

Submit Your Answer
Markdown supported