1. Lighthouse

Level 6 · Which channel's sales are steadier?

The request

From Kevin Brooks, Operations Manager

“I staff the packing team from a daily revenue forecast. Some channels feel predictable and some swing wildly from one day to the next. Which channel's daily sales are the steadiest, and which one should I plan for with the biggest buffer?”

Your goal

daily has one row per day from 2023-01-01 to 2025-12-31 and one column per channel, holding that day's completed revenue (0 on days without a sale). Set result to a DataFrame with one row per channel (sorted A to Z) and columns channel, mean and std of daily revenue (pandas defaults, rounded to 2), and cv: the standard deviation divided by the mean, rounded to 3.

  • Use the orders DataFramenot done yet
  • Use the order_items DataFramenot done yet
  • Show exactly channel mean std cvnot done yet
Completed revenue per day, by channel (2023 to 2025)
Completed revenue per day, by channel (2023 to 2025)$0$2k$4k$6k$8k$10kapp: median $1,219, middle half $383.78 to $2,611, 1,096 valuesappmarketplace: median $307.44, middle half $0 to $983.58, 1,096 valuesmarketplaceweb: median $2,092, middle half $997.11 to $3,825, 1,096 valueswebRevenue per day
Completed revenue per day, by channel (2023 to 2025)$0$2k$4k$6k$8k$10kapp: median $1,219, middle half $383.78 to $2,611, 1,096 valuesappmarketplace: median $307.44, middle half $0 to $983.58, 1,096 valuesmarketplaceweb: median $2,092, middle half $997.11 to $3,825, 1,096 valueswebRevenue per day

Each box holds the middle half of the 1,096 days; the line inside is the median day. Dots are unusually big days. A few days above $10,000 are not drawn.

Show the numbers
GroupValuesLower whiskerQ1MedianQ3Upper whiskerBeyond whiskers
app1,096$0$383.78$1,219$2,611$5,94356
marketplace1,096$0$0$307.44$983.58$2,45284
web1,096$0$997.11$2,092$3,825$8,03345

Your code

Python

Loading the editor…

    ResultPreview of orders · press Run to see yours
    Preview of orders
    order_idcustomer_idorder_datestatuschannel
    10011252023-01-01 20:51:19completedweb
    10021562023-01-02 07:58:46completedweb
    1003222023-01-02 10:25:27completedmarketplace
    1004482023-01-02 11:21:51completedmarketplace

    Mote checks your result

    Press Run. Each row that matches the goal becomes a firefly in your lantern.

    DataFrames

    Loaded for you as pandas DataFrames, plus pd and np.

    orders12,000 rows · 7 columns
    • order_idinteger
    • customer_idinteger
    • order_datetimestamp
    • statusvarchar
    • channelvarchar
    • shipping_feedecimal
    • coupon_codevarchar
    First 5 rows of orders
    order_idcustomer_idorder_datestatuschannelshipping_feecoupon_code
    10011252023-01-01 20:51:19completedweb0.00NaN
    10021562023-01-02 07:58:46completedweb0.00NaN
    1003222023-01-02 10:25:27completedmarketplace4.99WELCOME10
    1004482023-01-02 11:21:51completedmarketplace4.99WELCOME10
    1005822023-01-02 11:43:36completedweb0.00WELCOME10
    order_items30,338 rows · 6 columns
    • order_item_idinteger
    • order_idinteger
    • product_idinteger
    • quantityinteger
    • unit_pricedecimal
    • discount_pctdecimal
    First 5 rows of order_items
    order_item_idorder_idproduct_idquantityunit_pricediscount_pct
    11001121931.990.00
    21001154311.990.00
    31002154411.990.00
    410021941149.000.00
    51002193219.990.00
    customers2,018 rows · 9 columns
    • customer_idinteger
    • first_namevarchar
    • last_namevarchar
    • emailvarchar
    • cityvarchar
    • statevarchar
    • signup_datedate
    • segmentvarchar
    • referral_sourcevarchar
    First 5 rows of customers
    customer_idfirst_namelast_nameemailcitystatesignup_datesegmentreferral_source
    1OwenHudsonowen.hudson@icloud.comSan FranciscoCA2022-06-02consumersearch
    2DouglasMendozadmendoza69@gmail.comAtlantaGA2022-06-02consumerNaN
    3HenryBrookshbrooks@lakesidecafe.comLos AngelesCA2022-06-04businessNaN
    4BrianGrahambgraham@bluecedarhomes.comSeattleWA2022-06-06businesspinterest
    5KyleJimenezkjimenez27@yahoo.comIndianapolisIN2022-06-07consumerNaN
    products120 rows · 8 columns
    • product_idinteger
    • namevarchar
    • categoryvarchar
    • subcategoryvarchar
    • unit_pricedecimal
    • unit_costdecimal
    • launched_ondate
    • is_activeboolean
    First 5 rows of products
    product_idnamecategorysubcategoryunit_priceunit_costlaunched_onis_active
    101Vale Velvet LoveseatFurnitureSofas1659.00NaN2023-09-11true
    102Alder Oak Coffee TableFurnitureTables919.00503.502024-05-16true
    103Orchard Rattan Dining ChairFurnitureChairs789.00429.872023-05-27true
    104Upland Oak BookcaseFurnitureStorage429.00214.702022-12-20true
    105Avery Leather Bed FrameFurnitureBeds449.00232.702021-08-31true
    returns1,673 rows · 5 columns
    • return_idinteger
    • order_item_idinteger
    • returned_ondate
    • reasonvarchar
    • refund_amountdecimal
    First 5 rows of returns
    return_idorder_item_idreturned_onreasonrefund_amount
    1142023-01-10damaged83.69
    2422023-01-10wrong_item19.99
    31052023-01-14wrong_item10.99
    4242023-01-16changed_mind26.99
    51262023-01-16late20.99
    employees60 rows · 8 columns
    • employee_idinteger
    • first_namevarchar
    • last_namevarchar
    • departmentvarchar
    • titlevarchar
    • manager_idinteger
    • hire_datedate
    • salaryinteger
    First 5 rows of employees
    employee_idfirst_namelast_namedepartmenttitlemanager_idhire_datesalary
    1CatherineHaleExecutiveChief Executive OfficerNaN2016-03-01285000
    2RobertKimExecutiveChief Operating Officer12017-01-09235000
    3MeganCollinsSalesHead of Sales12018-04-16172000
    4ChloeGutierrezSalesAccount Executive32020-01-2172000
    5FrankBellSalesAccount Executive32023-05-2173000
    web_sessions40,000 rows · 7 columns
    • session_idinteger
    • customer_idinteger
    • started_attimestamp
    • devicevarchar
    • sourcevarchar
    • pages_viewedinteger
    • convertedboolean
    First 5 rows of web_sessions
    session_idcustomer_idstarted_atdevicesourcepages_viewedconverted
    1NaN2023-01-01 23:02:24mobilepaid1false
    2182023-01-01 15:07:49desktoppaid1false
    3NaN2023-01-01 16:55:46desktopdirect7false
    4NaN2023-01-01 12:43:28mobileorganic3false
    5NaN2023-01-01 13:06:21mobilesocial2false
    marketing_spend3,276 rows · 3 columns
    • spend_datedate
    • channelvarchar
    • amountdecimal
    First 5 rows of marketing_spend
    spend_datechannelamount
    2023-01-01paid492.99
    2023-01-01email37.38
    2023-01-01social200.53
    2023-01-02paid709.13
    2023-01-02email64.13

    The lesson

    Same average, different risk

    Imagine two stores that both sell $1,000 a day on average. In the first, most days land between $950 and $1,050. In the second, one day brings $400 and the next $1,800. The averages are equal; the businesses are not. The first can be staffed and stocked from the average; the second needs a buffer, because “average” is rarely what happens.

    The standard deviation from level 4 measures exactly that: the typical distance of a day from the average day. Small means predictable, large means volatile.

    Daily revenue per channel

    The starter builds daily: one row per calendar day, one column per channel. Taking the standard deviation of each column answers Kevin’s question:

    daily.mean()   # app 1847.38, marketplace 764.13, web 2766.49
    daily.std()    # app 2039.60, marketplace 1190.90, web 2502.56

    On every channel the standard deviation is about as large as the mean, or larger. Daily revenue here is driven by a few big business orders and by the November and December peaks, so a “normal day” is hard to define. The box plot shows it: the boxes are short and the dots above them run far.

    The coefficient of variation

    Web’s standard deviation ($2,503) is the largest, yet web also sells the most. To compare spread between groups of different size, divide the standard deviation by the mean. That ratio is the coefficient of variation (CV):

    cv = daily.std() / daily.mean()   # web 0.905, app 1.104, marketplace 1.559

    A CV of 0.9 means a typical day is about 90% of the average away from it. Web is the steadiest channel relative to its size; marketplace is the least predictable, with a typical swing of more than one and a half times its average day.

    Count the empty days

    Marketplace had no completed sale on 295 of the 1,096 days. If you group the orders by day without filling in those days, they disappear: the mean rises to $1,046 and the CV falls to 1.23, which makes the channel look steadier than it is. A day without sales is a real day with revenue 0. The starter’s reindex(...).fillna(0) puts them back.

    Common mistakes

    • Comparing standard deviations of groups with different means. Use the CV, or compare each group’s spread to its own average.
    • Dropping zero days. Grouping orders by day only creates the days that had orders. Build the full calendar first.
    • Using the CV on data that can be negative or average near zero. Dividing by a mean close to 0 makes the ratio explode; it is meant for positive quantities like revenue.
    • Reading volatility as bad. A channel with big swings may simply sell big items. It still needs more buffer in the plan.

    Pick what may run on this site. You can change this any time from "Cookie settings" at the bottom of every page.