…
…
Compare the four weeks before and the four weeks after a campus canteen's price increase, by item and by day; answer whether revenue or quantity fell, and whether the price caused it, using unchanged items as a benchmark and weighing the mean against the median.
Nadia, who runs a campus canteen, raised the prices of tea, filter coffee, toastie and bagel on July 1, when the summer session began. A month later she asks: "How have my sales done since the price increase? Did revenue go up, or did quantity fall? If it fell, was it because of the price increase?" She has the business-day sales for the four weeks before the increase (June 1–26) and the four weeks after (July 6–31). In this project you will first build the before and after tables and compare them by item and by day, and in the end you will separate what the data says from what it does not say.
Data: canteen_sales.csv (fictional sample data), 320 rows; each row is the sales of one item on one day (40 business days × 8 items).
| Column | Description |
|---|---|
date | Sales day (YYYY-MM-DD) |
weekday | Day of the week (Monday–Friday) |
item | Item name (tea, filter coffee, toastie, bagel, pastry, water, yogurt drink, fruit juice) |
category | hot drink, cold drink or food |
unit_price | Price in effect that day ($) |
quantity | Quantity sold that day |
Lessons used: reading CSV, conditional assignment and new columns (4–6); grouping, pivot tables and before/after comparison (7–10); mean and median (12); weighted average (13).
Cells share one session: each step works with the df and the variables defined by the previous one.
What you'll do
canteen_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.
Nadia, who runs a campus canteen, raised the prices of four items on July 1 when the summer session began. A month later she asks: "How have my sales done since the price increase?" Her table is canteen_sales.csv: each row is the sales of one item on one day.
To compare, you first need two things: which period each row belongs to (before or after the increase) and the money each row brought in, the revenue. The table has no revenue column; you will derive it from the quantity and the unit price.
Finally, count how many business days each period has. If the two periods had a different number of days, comparing the totals directly would be unfair.
This step's code cell is for members.Sign up free
Nadia says "I raised four items"; check this against the data. Build a table that puts the price of each item in the two periods side by side and compute the percent price change (the pivot table from lesson 8).
Save the list of items with a price increase in a variable: in the next steps you will compare the raised items with the others. The items without an increase will be very useful in this project.
This step's code cell is for members.Sign up free
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 first big question: after the price increase, did the canteen sell fewer items, earn less money, or both? Compute the total quantity and total revenue for each period, turn them into daily averages and compute the percent change (the before/after table from lesson 10).
Also compute the average price per item sold: total revenue divided by total quantity. This is a weighted average by quantity (lesson 13): the price of an item that sells a lot affects the result more.
Then write the letter of the correct sentence into the variable verdict:
This step's code cell is for members.Sign up free
Is the total drop spread evenly across the items? Build a table with the total quantity of each item in the two periods and the percent change, sorted so that the item with the sharpest drop is at the top.
While you read the table, keep the list of raised items from step 2 next to it: which items are near the top of the list, which near the bottom? What happened to the quantity of items whose price never changed?
This step's code cell is for members.Sign up free
The question on Nadia's mind is: "Did sales fall because of the price increase?" You cannot answer it by looking only at the raised items, because more than the price changed in July: the spring term ended and the summer session started.
Here the four items whose price did not change give you a comparison group. If the quantity of the unchanged items fell too, that drop cannot come from the price; it comes from the period itself. If you subtract the drop of the unchanged items from the drop of the raised items, you roughly see the most that can be put on the price increase.
Split the items into two groups, compute the quantity change per group, and find the difference in percentage points. Then write the letter of the correct reading into the variable verdict_raise:
This step's code cell is for members.Sign up free
In her report, Nadia also wants the answer to "how much revenue does the canteen make on a typical day?" For that, first add the rows up by day: one revenue figure for each day.
Look at the days with the highest revenue: one stands far apart from the rest. That day there was a graduation ceremony on campus. Compute both the mean and the median of daily revenue for each period (lesson 12) and compare the percent change under the two measures.
Then decide: which measure will you report for a "typical day"? Write your answer into the variable measure as "mean" or "median".
This step's code cell is for members.Sign up free
Write what you found to Nadia in three sentences: (1) what quantity and revenue did, (2) whether this drop is because of the price increase, (3) one thing this data does not say. Write the text in the report field of the cell; this part is not checked automatically.
Checklist
Weak example: "Sales fell 43% because of the price increase. If we lower the prices again, sales will go back to how they were." Why it is weak: the unchanged items also fell 37%; most of the drop comes with the change of period. On top of that, the 43% is a total inflated by the graduation day in the before period.
The checked part: the cell prints eight sentences. This data says four of them and does not say the other four. Write the letters of the ones it says into the list says, and those of the ones it does not say into the list does_not_say.
Quick review (no points)
Unchanged items fell 37.5%, raised items fell 46.8%. Which sentence about the 9-point gap is the most honest?
Total quantity fell 43.2%, but the drop would come out smaller if you looked at the median of daily quantity. Why?
If you applied the same method to a price change on a cafe menu, which step would matter most?
This step's code cell is for members.Sign up free