← Amazon Interview Insights

Amazon·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Amazon Data Scientist technical screen, one meaty pandas question that looked straightforward on the surface but had enough moving parts to trip you up if you weren't careful about the groupby-rolling interaction.

Questions Asked (1)

Q1

Given a daily sales table with product IDs, units sold, and revenue, write pandas code to compute a 3-day rolling average of revenue per product, pivot the result so dates are rows and product IDs are columns, and merge in the total units sold per product.

Product Analytics & MetricsAlgorithms & Data StructuresData Modeling
Author's notes

The rolling part is where I fumbled.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the data schema and assumptions (e.g., date granularity, missing dates, product coverage). Then outline a pandas pipeline: sort by product and date, compute rolling average per product, pivot to date-by-product matrix, and merge aggregated units sold per product. Finally, discuss edge cases like missing dates and how to handle them.

Pro tip: Mention that you would verify the rolling window is computed on a complete date range per product (reindexing to fill missing dates) to avoid incorrect averages, and that you'd use merge with how='left' to preserve all dates.

1. Clarify data and assumptions

Confirm the table schema, date frequency, and whether each product has data for every date. Ask about handling missing dates and whether the rolling average should be computed on calendar days or available data points.

2. Compute rolling average per product

Sort by product_id and date, then use groupby('product_id')['revenue'].rolling(window=3, min_periods=1).mean() to compute the 3-day rolling average. Reset index to flatten the result.

3. Pivot to date-by-product matrix

Use pivot_table or pivot with index='date', columns='product_id', values='rolling_avg_revenue' to reshape the data so each row is a date and each column is a product.

4. Aggregate and merge total units sold

Compute total units sold per product using groupby('product_id')['units_sold'].sum(), then merge this as a new row or column into the pivoted DataFrame, ensuring alignment with product columns.

5. Validate and discuss edge cases

Check for missing values, verify the rolling window logic, and discuss how to handle products with insufficient history. Mention potential performance considerations for large datasets.

Key Points to Mention

  • Use of groupby with rolling window and min_periods to handle initial days
  • Sorting by date within each product before rolling to ensure correct order
  • Pivot using pivot_table or pivot, and resetting index/columns as needed
  • Merging total units sold per product, possibly as an additional row or column
  • Handling missing dates by reindexing to a complete date range per product
  • Performance considerations: using vectorized operations and avoiding loops

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.