Chapter 10 · 8 levels
Time series
Turn timestamps into trends with resample, rolling windows, period-over-period growth, date offsets and gap filling, on three years of Harbor & Pine orders.
StartAlmost every report an analyst sends has time on one axis: orders per month, revenue per week, a
seven-day average on a dashboard, this November against last November. pandas has a whole toolkit
for this, built around a DatetimeIndex: once the timestamps are the index, you can regroup them
into any calendar period, slide windows across them and compare a period with the one before.
Harbor & Pine’s data covers three full years, 2023 to 2025, with a strong holiday season and a
Black Friday spike, so the trends are real enough to be worth finding. You’ll count orders per
month with resample, build monthly revenue, smooth a noisy daily series with rolling, measure
month-over-month and year-over-year growth, work with date offsets like “30 days after the order”,
and find and fill gaps in the marketing spend log.
The chapter ends with a boss level: a holiday-season review for the CEO, built from daily revenue, rolling windows and year-over-year growth.
Levels
- Orders per month with resample
from Megan Collins, Head of Sales
datetimeindex, resample, set index, month start, size
- Monthly revenue from order lines
from Laura Bennett, Head of Finance
resample, merge, sum, month start, line revenue
- A 7-day average for the dashboard
from Jordan Reyes, Head of Marketing
rolling, moving average, resample daily, window, min periods
- Month over month and year over year
from Catherine Hale, Chief Executive Officer
pct change, shift, month over month, year over year, seasonality
- How long until a return?
from Angela Rivera, Head of Customer Support
timedelta, dt days, date offset, normalize, return window
- Find and fill the tracking gaps
from Jordan Reyes, Head of Marketing
asfreq, date range, reindex, ffill, fillna, missing dates
- Why don't the targets line up?
from Megan Collins, Head of Sales
resample, month end, month start, merge, period
- Boss: the holiday season review
from Catherine Hale, Chief Executive Officer
rolling, day name, month name, calendar order, strftime, quarter, year over year