A time series is one number per stretch of time, in order: here, the shop's revenue per week. But orders.csv has one row per order line, each with a date. To get one row per week, pandas needs real dates, the dates as row labels, and a way to add up each week.
pd.to_datetime(column) reads texts like "2026-03-14" and gives back a column of real dates. df.set_index("date") gives back the same rows, labeled by their date instead of 0, 1, 2…: a date index. On a Series with a date index, .resample("W") puts the rows into weeks, Monday to Sunday, and .sum() gives back one total per week, labeled by the Sunday the week ends on. A week with no rows still gets its row, with 0.
visits = pd.DataFrame({"day": ["2026-03-02", "2026-03-04", "2026-03-09"], "count": [5, 3, 4]})
visits["day"] = pd.to_datetime(visits["day"])
per_week = visits.set_index("day")["count"].resample("W").sum()
# week ending 2026-03-08: 8 (5 + 3), week ending 2026-03-15: 4
.tail(n) gives back the last n rows, as .head(n) does the first. len(series) is its number of rows. series.max() gives back the biggest value, and series.idxmax() gives back its label, here a date; .date() drops the time of day from it.
Your program must print (Freq: W-SUN is pandas saying the rows are weeks ending on Sunday):
date 2026-01-04 23 2026-01-11 215 2026-01-18 16 2026-01-25 0 Freq: W-SUN date 2026-11-22 2671 2026-11-29 3090 Freq: W-SUN Weeks: 48 Best week: 2026-11-08 3549
Your task: the starting code reads orders.csv, works out each line's revenue and keeps the paid lines. Turn date into real dates, label the paid rows by their date in by_date, add up their revenue per week into weekly, then print the first 4 weeks, the last 2, the number of weeks and the best week.
Assignment
Follow the Coding Tutorial to add up the shop's paid revenue week by week and print what it shows.
Hint
Turn the dates into real dates first: resample only works on a date index. idxmax() gives back a date with a time of day; .date() keeps only the day.
Free plan: 30 tutor messages. PRO is unlimited.
