← All Python interview questions
Report week-over-week growth in orders
MediumDates & Time SeriesZeptoPhonePe
The weekly business review needs order growth versus the previous week.
Write wow_growth(df) that resamples the daily orders column into weekly totals (weeks ending Sunday) and returns a Series of the percentage change versus the previous week, rounded to 1 decimal. The first week has no prior week, so it must be 0.0.
This fixture runs before your code on every Run and Submit, so the data is always clean.
import pandas as pd
daily_orders = pd.DataFrame({
"day": pd.date_range("2026-01-05", periods=21, freq="D"),
"orders": [
10, 12, 11, 13, 14, 20, 20,
12, 14, 13, 15, 16, 22, 23,
11, 11, 12, 12, 13, 18, 18,
],
})- Step 1: `resample('W-SUN')` buckets by week ending Sunday — the anchor matters, because a Monday-anchored week produces different numbers from the same data.
- Step 2: `pct_change()` divides each week by the previous one and subtracts 1, so multiplying by 100 gives a percentage.
- Step 3: The first week has no predecessor and is `NaN`; `fillna(0.0)` makes the series safe to chart without a gap.
- Step 4: Rounding at the end keeps the arithmetic exact until the moment of display.
def wow_growth(df):
weekly = df.set_index("day")["orders"].sort_index().resample("W-SUN").sum()
return (weekly.pct_change() * 100).round(1).fillna(0.0)Learn the concept first
Stuck on Dates & Time Series? These free Python lessons teach it step by step.
Practising alone only goes so far — our live cohorts pair Python and Pandas depth with dashboards, agentic analytics projects and mock interviews.
Explore the program