…
…
Add up a year of daily sales from a small bookshop into weeks and months, separate the day-of-the-week cycle from a one-day jump, and write the owner an honest report with the change from the previous week.
Quill Books and Stationery is a small shop near a university campus. The owner brought a year of till records: "I look at the numbers every day, but I feel happy one day and worried the next. How are my sales really going, and what should I look at every Monday?" The assistant at the till has opinions too: on Mondays they say "revenue exploded compared with yesterday", and they noted one day in March as "business picked up". Your job is to find the path under the daily noise and give the owner a report that says only as much as the data carries.
Data: daily_sales.csv (fictional sample data), January 1 to December 31, 2025, one row per day (365 rows).
| Column | Description |
|---|---|
date | The day (YYYY-MM-DD) |
receipts | Number of receipts (purchases) that day |
revenue | Total sales for that day ($) |
Product: a monthly and a weekly table, a chart of the 7-day moving average, and a short note in step 8 made of the sentences the data supports.
Lessons used: date columns and the day of the week (6), grouping and summaries (7), combining tables (9), time series: date index, resample, moving average, and pct_change against the previous day, the same day last week and the previous week (41), correlation and causation (37, only in the comment of the last step).
Cells share one session; each step uses the variables of the one before.
What you'll do
Required topics
daily_sales.csvDownload file
Reading file…
Code cells are for members
You can read the steps. Sign up free to run the code, complete the steps and save your progress.
The owner of Quill Books and Stationery gave you a year of till records and asks one thing: "How are my sales really going, and what should I look at?" Before you look at daily numbers, open the table as a time series: the date must be read as a real date, not as text, and it must be the row label.
Read daily_sales.csv as s, with the date column parsed as dates and used as the index of the table. Then print the number of days and the first and last date. A year has 365 days: with missing days, the weekly and monthly totals would mislead.
This step's code cell is for members.Sign up free
The owner's first question: "Which month is best and which is worst?" Add the days up by month: receipts and revenue for each month. Then add the average basket (revenue per receipt, in dollars) as a basket column.
The average basket is a ratio: a month's value is the month's total revenue divided by the month's total receipts, not the average of the daily baskets (lesson 41). Finally, find the months with the highest and the lowest revenue.
Look at the basket for March in the table: its receipt count is close to April's, but its basket is about $1 higher. You will see why in step 6.
This step's code cell is for members.
Code cells are for members
You can read the steps. Sign up free to run the code, complete the steps and save your progress.
The owner wants to look at last week's revenue every Monday. Add the days up into weeks that end on Sunday. For each week, keep the revenue total and the number of days in the week in a weekly table.
January 1 and December 31 are both Wednesdays that year, so the first and the last week have only a few days. Incomplete weeks look like false drops in a weekly comparison. Keep only the weeks with all 7 days in full. In the next steps, you will do the weekly comparison on full.
This step's code cell is for members.Sign up free
The cashier's assistant writes a happy note every Monday: "Revenue is up more than 50% from yesterday again!" First look at the store's weekly cycle: the mean receipts and revenue for each day of the week. Add the day names to the means by using the ready-made names table and the shared weekday_no column (0 = Monday), so they are easy to read (lesson 9).
Then test the assistant's sentence: find the days when revenue rose by more than 50% from the day before, and count which days of the week they fall on. Is most of this growth a real improvement, or is it the weekly cycle itself?
This step's code cell is for members.Sign up free
Daily revenue looks like a saw blade: peak on Saturday, dip on Sunday. What the owner really wants to see is the path under those teeth. Compute the 7-day moving average of revenue as ma7. Every seven-day window contains exactly one of each weekday, so the weekly cycle cancels out.
Then find the quietest and the busiest period of the year: the days when the moving average is lowest and highest. The cell draws daily revenue as a thin line and the moving average as a thick line in the same chart. You write the title as the one sentence the chart says.
This step's code cell is for members.Sign up free
This time the assistant found a day in March: "Revenue is five times higher that day. Business picked up in March!" To avoid the weekday effect, compare each day with the same day last week (pct_change(7), as a percentage) and find the day with the largest change. Look at that day's receipt count and average basket too.
Then test whether the level really changed, using ma7 from step 5: the day before the jump (the window does not include the jump), the day of the jump, and exactly seven days after the jump (the window starts one day after the jump).
Finally, write the letter of the best explanation in the variable comment:
This step's code cell is for members.Sign up free
We only have one year, so we cannot compare with the same week last year. The comparison the owner can use in a Monday report is the change from the previous week: a weekly total contains one of each weekday, so the weekday effect cancels out by itself.
Compute the percent change of the full-week revenue totals from step 3 against the previous week as change (1 decimal). Then find the week with the largest increase and the week with the largest decrease, and look at the change for the week that contains March 12 and for the week after it.
How can a single day move a weekly report? If the jump week shows an increase and the next week shows a "drop" of almost the same size, is the second one a real drop?
This step's code cell is for members.Sign up free
You will write a short note to the owner. Every sentence in the note must stay within what the data carries. From the sentences below, choose the ones this one-year data can support and write their letters in the set supported:
A small test: compute the September to July ratio yourself and keep it as ratio (1 decimal).
Three questions to ask yourself: Does the sentence only describe what happened, or does it describe a cause or the future? Can one year of data show a yearly cycle (a September increase that repeats every year)? Does a single day prove a change of level?
This step's code cell is for members.Sign up free