Compute 3-Day Rolling Revenue Averages with Pandas
Company: Amazon
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Onsite
Overview: This question evaluates proficiency with Python pandas for time-series data manipulation, specifically group-wise aggregation, rolling-window calculations, pivoting, and merging summary statistics.
Tables
sales(date DATE, product_id INTEGER, units INTEGER, revenue DECIMAL(10,2))
Hints
- Use a window function with ROWS BETWEEN 2 PRECEDING AND CURRENT ROW to compute the 3-row rolling average per product_id.
- Use another window SUM over units partitioned by product_id to get total units per product.