The request

From Laura Bennett, Head of Finance
Your goal
Build daily revenue for 2025 from completed orders (line revenue = quantity × unit_price × (1 − discount_pct / 100)), with one value per calendar day. Then take a 7-day rolling mean. Set result to a dict: "busiest_day", the date with the highest daily revenue, and "busiest_week_end", the date where the 7-day mean is highest, both as "YYYY-MM-DD" text, and "max_7day", that highest 7-day mean, rounded to 2.
- Use the
ordersDataFramenot done yet - Use the
order_itemsDataFramenot done yet - Store a dict in
resultnot done yet
One point per day. Single big orders make spikes that say little about the trend.
Show the numbers
| revenue | |
|---|---|
| Oct 01 | $7,274 |
| Oct 02 | $2,112 |
| Oct 03 | $4,680 |
| Oct 04 | $2,781 |
| Oct 05 | $3,477 |
| Oct 06 | $2,683 |
| Oct 07 | $3,333 |
| Oct 08 | $6,183 |
| Oct 09 | $9,080 |
| Oct 10 | $13,463 |
| Oct 11 | $2,566 |
| Oct 12 | $4,713 |
| Oct 13 | $6,800 |
| Oct 14 | $9,910 |
| Oct 15 | $6,526 |
| Oct 16 | $3,814 |
| Oct 17 | $8,680 |
| Oct 18 | $7,353 |
| Oct 19 | $1,924 |
| Oct 20 | $2,019 |
| Oct 21 | $6,832 |
| Oct 22 | $3,267 |
| Oct 23 | $1,675 |
| Oct 24 | $6,266 |
| Oct 25 | $12,136 |
| Oct 26 | $6,223 |
| Oct 27 | $6,582 |
| Oct 28 | $5,525 |
| Oct 29 | $5,992 |
| Oct 30 | $3,587 |
| Oct 31 | $7,148 |
| Nov 01 | $13,803 |
| Nov 02 | $9,265 |
| Nov 03 | $8,846 |
| Nov 04 | $4,958 |
| Nov 05 | $6,880 |
| Nov 06 | $6,287 |
| Nov 07 | $6,646 |
| Nov 08 | $5,912 |
| Nov 09 | $7,314 |
| Nov 10 | $13,755 |
| Nov 11 | $6,441 |
| Nov 12 | $10,065 |
| Nov 13 | $5,885 |
| Nov 14 | $5,975 |
| Nov 15 | $16,267 |
| Nov 16 | $8,817 |
| Nov 17 | $10,937 |
| Nov 18 | $15,139 |
| Nov 19 | $6,540 |
| Nov 20 | $12,074 |
| Nov 21 | $10,664 |
| Nov 22 | $6,574 |
| Nov 23 | $14,407 |
| Nov 24 | $5,660 |
| Nov 25 | $4,173 |
| Nov 26 | $4,801 |
| Nov 27 | $11,165 |
| Nov 28 | $15,976 |
| Nov 29 | $19,382 |
| Nov 30 | $17,757 |
| Dec 01 | $23,299 |
| Dec 02 | $7,703 |
| Dec 03 | $6,354 |
| Dec 04 | $13,797 |
| Dec 05 | $8,518 |
| Dec 06 | $13,459 |
| Dec 07 | $15,360 |
| Dec 08 | $11,234 |
| Dec 09 | $3,319 |
| Dec 10 | $9,526 |
| Dec 11 | $11,364 |
| Dec 12 | $9,434 |
| Dec 13 | $22,028 |
| Dec 14 | $8,486 |
| Dec 15 | $7,621 |
| Dec 16 | $16,117 |
| Dec 17 | $13,730 |
| Dec 18 | $6,980 |
| Dec 19 | $6,694 |
| Dec 20 | $14,178 |
| Dec 21 | $9,817 |
| Dec 22 | $6,037 |
| Dec 23 | $5,782 |
| Dec 24 | $5,647 |
| Dec 25 | $1,597 |
| Dec 26 | $6,528 |
| Dec 27 | $5,232 |
| Dec 28 | $6,396 |
| Dec 29 | $1,635 |
| Dec 30 | $3,416 |
| Dec 31 | $7,059 |
Your code
Loading the editor…
Reference solution
| order_id | customer_id | order_date | status | channel |
|---|---|---|---|---|
| 1001 | 125 | 2023-01-01 20:51:19 | completed | web |
| 1002 | 156 | 2023-01-02 07:58:46 | completed | web |
| 1003 | 22 | 2023-01-02 10:25:27 | completed | marketplace |
| 1004 | 48 | 2023-01-02 11:21:51 | completed | marketplace |
Mote checks your result
Press Run. Each row that matches the goal becomes a firefly in your lantern.
What Laura gets, and why
Each point is the mean of that day and the six before it. The rush builds from mid-November and peaks in the first week of December.
Show the numbers
| avg_7day | |
|---|---|
| Oct 01 | $5,824 |
| Oct 02 | $5,354 |
| Oct 03 | $5,506 |
| Oct 04 | $4,601 |
| Oct 05 | $3,973 |
| Oct 06 | $3,771 |
| Oct 07 | $3,763 |
| Oct 08 | $3,607 |
| Oct 09 | $4,602 |
| Oct 10 | $5,857 |
| Oct 11 | $5,826 |
| Oct 12 | $6,003 |
| Oct 13 | $6,591 |
| Oct 14 | $7,531 |
| Oct 15 | $7,579 |
| Oct 16 | $6,827 |
| Oct 17 | $6,144 |
| Oct 18 | $6,828 |
| Oct 19 | $6,429 |
| Oct 20 | $5,746 |
| Oct 21 | $5,307 |
| Oct 22 | $4,841 |
| Oct 23 | $4,536 |
| Oct 24 | $4,191 |
| Oct 25 | $4,874 |
| Oct 26 | $5,488 |
| Oct 27 | $6,140 |
| Oct 28 | $5,953 |
| Oct 29 | $6,343 |
| Oct 30 | $6,616 |
| Oct 31 | $6,742 |
| Nov 01 | $6,980 |
| Nov 02 | $7,415 |
| Nov 03 | $7,738 |
| Nov 04 | $7,657 |
| Nov 05 | $7,784 |
| Nov 06 | $8,169 |
| Nov 07 | $8,098 |
| Nov 08 | $6,971 |
| Nov 09 | $6,692 |
| Nov 10 | $7,393 |
| Nov 11 | $7,605 |
| Nov 12 | $8,060 |
| Nov 13 | $8,003 |
| Nov 14 | $7,907 |
| Nov 15 | $9,386 |
| Nov 16 | $9,601 |
| Nov 17 | $9,198 |
| Nov 18 | $10,441 |
| Nov 19 | $9,937 |
| Nov 20 | $10,821 |
| Nov 21 | $11,491 |
| Nov 22 | $10,107 |
| Nov 23 | $10,905 |
| Nov 24 | $10,151 |
| Nov 25 | $8,585 |
| Nov 26 | $8,336 |
| Nov 27 | $8,206 |
| Nov 28 | $8,965 |
| Nov 29 | $10,795 |
| Nov 30 | $11,273 |
| Dec 01 | $13,793 |
| Dec 02 | $14,298 |
| Dec 03 | $14,519 |
| Dec 04 | $14,895 |
| Dec 05 | $13,830 |
| Dec 06 | $12,984 |
| Dec 07 | $12,641 |
| Dec 08 | $10,918 |
| Dec 09 | $10,291 |
| Dec 10 | $10,745 |
| Dec 11 | $10,397 |
| Dec 12 | $10,528 |
| Dec 13 | $11,752 |
| Dec 14 | $10,770 |
| Dec 15 | $10,254 |
| Dec 16 | $12,082 |
| Dec 17 | $12,683 |
| Dec 18 | $12,057 |
| Dec 19 | $11,665 |
| Dec 20 | $10,544 |
| Dec 21 | $10,734 |
| Dec 22 | $10,508 |
| Dec 23 | $9,031 |
| Dec 24 | $7,876 |
| Dec 25 | $7,107 |
| Dec 26 | $7,084 |
| Dec 27 | $5,806 |
| Dec 28 | $5,317 |
| Dec 29 | $4,688 |
| Dec 30 | $4,350 |
| Dec 31 | $4,552 |
DataFrames
Loaded for you as pandas DataFrames, plus pd and np.
orders12,000 rows · 7 columns
order_idintegercustomer_idintegerorder_datetimestampstatusvarcharchannelvarcharshipping_feedecimalcoupon_codevarchar
| order_id | customer_id | order_date | status | channel | shipping_fee | coupon_code |
|---|---|---|---|---|---|---|
| 1001 | 125 | 2023-01-01 20:51:19 | completed | web | 0.00 | NaN |
| 1002 | 156 | 2023-01-02 07:58:46 | completed | web | 0.00 | NaN |
| 1003 | 22 | 2023-01-02 10:25:27 | completed | marketplace | 4.99 | WELCOME10 |
| 1004 | 48 | 2023-01-02 11:21:51 | completed | marketplace | 4.99 | WELCOME10 |
| 1005 | 82 | 2023-01-02 11:43:36 | completed | web | 0.00 | WELCOME10 |
order_items30,338 rows · 6 columns
order_item_idintegerorder_idintegerproduct_idintegerquantityintegerunit_pricedecimaldiscount_pctdecimal
| order_item_id | order_id | product_id | quantity | unit_price | discount_pct |
|---|---|---|---|---|---|
| 1 | 1001 | 121 | 9 | 31.99 | 0.00 |
| 2 | 1001 | 154 | 3 | 11.99 | 0.00 |
| 3 | 1002 | 154 | 4 | 11.99 | 0.00 |
| 4 | 1002 | 194 | 1 | 149.00 | 0.00 |
| 5 | 1002 | 193 | 2 | 19.99 | 0.00 |
customers2,018 rows · 9 columns
customer_idintegerfirst_namevarcharlast_namevarcharemailvarcharcityvarcharstatevarcharsignup_datedatesegmentvarcharreferral_sourcevarchar
| customer_id | first_name | last_name | city | state | signup_date | segment | referral_source | |
|---|---|---|---|---|---|---|---|---|
| 1 | Owen | Hudson | owen.hudson@icloud.com | San Francisco | CA | 2022-06-02 | consumer | search |
| 2 | Douglas | Mendoza | dmendoza69@gmail.com | Atlanta | GA | 2022-06-02 | consumer | NaN |
| 3 | Henry | Brooks | hbrooks@lakesidecafe.com | Los Angeles | CA | 2022-06-04 | business | NaN |
| 4 | Brian | Graham | bgraham@bluecedarhomes.com | Seattle | WA | 2022-06-06 | business | |
| 5 | Kyle | Jimenez | kjimenez27@yahoo.com | Indianapolis | IN | 2022-06-07 | consumer | NaN |
products120 rows · 8 columns
product_idintegernamevarcharcategoryvarcharsubcategoryvarcharunit_pricedecimalunit_costdecimallaunched_ondateis_activeboolean
| product_id | name | category | subcategory | unit_price | unit_cost | launched_on | is_active |
|---|---|---|---|---|---|---|---|
| 101 | Vale Velvet Loveseat | Furniture | Sofas | 1659.00 | NaN | 2023-09-11 | true |
| 102 | Alder Oak Coffee Table | Furniture | Tables | 919.00 | 503.50 | 2024-05-16 | true |
| 103 | Orchard Rattan Dining Chair | Furniture | Chairs | 789.00 | 429.87 | 2023-05-27 | true |
| 104 | Upland Oak Bookcase | Furniture | Storage | 429.00 | 214.70 | 2022-12-20 | true |
| 105 | Avery Leather Bed Frame | Furniture | Beds | 449.00 | 232.70 | 2021-08-31 | true |
returns1,673 rows · 5 columns
return_idintegerorder_item_idintegerreturned_ondatereasonvarcharrefund_amountdecimal
| return_id | order_item_id | returned_on | reason | refund_amount |
|---|---|---|---|---|
| 1 | 14 | 2023-01-10 | damaged | 83.69 |
| 2 | 42 | 2023-01-10 | wrong_item | 19.99 |
| 3 | 105 | 2023-01-14 | wrong_item | 10.99 |
| 4 | 24 | 2023-01-16 | changed_mind | 26.99 |
| 5 | 126 | 2023-01-16 | late | 20.99 |
employees60 rows · 8 columns
employee_idintegerfirst_namevarcharlast_namevarchardepartmentvarchartitlevarcharmanager_idintegerhire_datedatesalaryinteger
| employee_id | first_name | last_name | department | title | manager_id | hire_date | salary |
|---|---|---|---|---|---|---|---|
| 1 | Catherine | Hale | Executive | Chief Executive Officer | NaN | 2016-03-01 | 285000 |
| 2 | Robert | Kim | Executive | Chief Operating Officer | 1 | 2017-01-09 | 235000 |
| 3 | Megan | Collins | Sales | Head of Sales | 1 | 2018-04-16 | 172000 |
| 4 | Chloe | Gutierrez | Sales | Account Executive | 3 | 2020-01-21 | 72000 |
| 5 | Frank | Bell | Sales | Account Executive | 3 | 2023-05-21 | 73000 |
web_sessions40,000 rows · 7 columns
session_idintegercustomer_idintegerstarted_attimestampdevicevarcharsourcevarcharpages_viewedintegerconvertedboolean
| session_id | customer_id | started_at | device | source | pages_viewed | converted |
|---|---|---|---|---|---|---|
| 1 | NaN | 2023-01-01 23:02:24 | mobile | paid | 1 | false |
| 2 | 18 | 2023-01-01 15:07:49 | desktop | paid | 1 | false |
| 3 | NaN | 2023-01-01 16:55:46 | desktop | direct | 7 | false |
| 4 | NaN | 2023-01-01 12:43:28 | mobile | organic | 3 | false |
| 5 | NaN | 2023-01-01 13:06:21 | mobile | social | 2 | false |
marketing_spend3,276 rows · 3 columns
spend_datedatechannelvarcharamountdecimal
| spend_date | channel | amount |
|---|---|---|
| 2023-01-01 | paid | 492.99 |
| 2023-01-01 | 37.38 | |
| 2023-01-01 | social | 200.53 |
| 2023-01-02 | paid | 709.13 |
| 2023-01-02 | 64.13 |
The lesson
Why daily charts are noisy
A day’s revenue depends on a few dozen orders. One business customer buying a sofa set can double a Tuesday. Weekdays and weekends differ too. Plot every day and the line zigzags so much that the real movement, the slow build of the holiday season, hides behind single spikes. Readers then point at the tallest spike and tell a story about it.
From orders to days
order_date is a timestamp with a time of day, so grouping by it gives one group per order time.
resample cuts a datetime index into calendar periods and fills days without orders with zero:
daily = lines.set_index("order_date").resample("D")["revenue"].sum()
len(daily) # 365: one value per day of 2025
"D" is days, "W" weeks, "MS" months starting on the 1st.
A 7-day rolling mean
rolling(7) slides a window of seven rows along the Series. .mean() averages each window and
labels it with its last day:
smooth = daily.rolling(7).mean()
smooth.head(7) # six NaN, then the mean of Jan 1 to Jan 7
The first six values are missing because there aren’t seven days yet. Seven is the usual window for daily business data: every window holds each weekday exactly once, so the weekly rhythm cancels out and what’s left is the trend.
Reading the smoothed line
The smoothed value on December 4 is the average of November 28 to December 4: the week after Thanksgiving, with Black Friday, Cyber Monday and their BFCM25 coupon orders inside it. That’s the busiest week of 2025. The single busiest day, December 1, is part of it, but a single day is a weaker signal. Notice that the smoothed line lags: it peaks a few days after the rush starts, because each point looks back over a week.
Common mistakes
- Rolling over rows that aren’t days. If days with no orders are missing,
rolling(7)spans more than a week. Resample first so there is exactly one row per day. - Centring by accident, or not at all.
rolling(7, center=True)labels each window with its middle day, which removes the lag but uses future days. Say which one your chart shows. - Smoothing away the thing you were asked about. If the question is “what happened on Black Friday?”, show the daily bars. Smoothing answers questions about trends.
Lantern lit!
Practised: rolling averageresampletime seriessmoothing
- Solved
- No hints
- First run
