Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Lab 3: Exploratory Analysis with Plotly

Open In Colab

Lab 3: Exploratory Analysis with Plotly

In this lab you summarise a real-looking service dataset and explore it with interactive charts, then use what you find to make a decision.

The question. In 2025 Qahwa House timed one order in five in its four branches. The manager wants to print “served within N minutes” on the menu boards of the whole chain. What should N be, and what must change first?

How this lab works

  • Run the cells from top to bottom with Shift + Enter.

  • Guided track: replace every ... with your code, then run the check cell under it. A ✅ means your answer is right.

  • Extended track: after Part D, try the ★ challenges at the end.

  • Submit before the next lab session: File → Download → Download .ipynb, then upload the file to the course page.

You may use an AI assistant for code. If you do, add a short note at the end of the notebook: what you asked, what you kept and what you changed.

Setup

Run the next two cells: the first loads Plotly, the charting library of this lab; the second downloads the data.

ColumnMeaning
date, weekday, hourwhen the order was paid
branch, citywhere
channelCounter, App or Drive-thru
items, order_valuehow many items, and the amount paid (SAR)
wait_minminutes from payment to the cup in the customer’s hand

Part A: Categorical data

A1. How do customers order?

Use value_counts(normalize=True) on the channel column and multiply by 100 to get percentages. Store the result in channel_pct.

A2. Channels by branch

Percentages within each branch: group by branch, then take value_counts(normalize=True) of channel, and .unstack(fill_value=0) to get one row per branch. Store it in mix. Which branches have a drive-thru?

Part B: Centre and spread of the wait

B1. Centre

Store the waiting times in w, then compute their mean and median. Which is larger, and why?

B2. Spread

Compute the interquartile range (quantile(0.75) - quantile(0.25)) and the sample standard deviation (.std()).

B3. The 90th percentile

Compute the 90th percentile of the waits. Then compute the share of customers who wait longer than the mean. Is it half?

Part C: Pictures with Plotly

plotly.express (imported as px) draws a whole chart in one line. In Colab you can hover over a bar for its value, zoom by dragging, and click a legend entry to hide a group.

C1. A histogram, and its bin width

Run the cell. Then change nbins to 8 and to 200 and run it again each time. Which bin width shows the shape best?

C2. Box plots by branch

Draw one box per branch with px.box(orders, x="wait_min", y="branch"). Store the figure in fig_box, then show it. Which branch has the longest tail?

C3. Orders per week

Count orders per full week (Sunday to Saturday) and plot them against time. The first and last weeks of the year are partial, so drop them with .iloc[1:-1].

C4. When in the day?

Run the cell: it compares the share of orders per hour on normal days and in Ramadan (1 to 29 March 2025, approximately).

Part D: The decision

D1. One row per branch

Build a table promise with one row per branch and four columns: the mean wait, the median, the 90th percentile p90, and over_8, the percentage of orders that wait more than 8 minutes. Sort it by p90.

D2. What would a promise based on the mean cost?

For each branch, the percentage of orders that would break a promise of 5 minutes (about the chain’s mean wait). Store it in broken_at_5.

D3. Your recommendation

Write three sentences for the manager, who does not read code:

  1. what the data shows, with one or two numbers;

  2. the value of N you recommend, and for which branches;

  3. what must change, or what the data cannot tell us, before the promise is safe everywhere.

Write your recommendation here (double-click to edit).

★ Extended challenges

E1. Rush hours. Compare the median and the 90th percentile of the wait in the rush hours (7, 8, 20 and 21) and at other times. Is the rush a reason to staff differently, or only to promise differently?

E2. Exam months at University. Compare University’s 90th percentile in its exam months (January, May, June, December) with the other months. Does the tail come from the whole year?

E3. The typical basket. Is order_value skewed? Which number would you report as the “typical basket”, and which one would you use to estimate the chain’s annual revenue from this sample?

AI-use log (if you used an AI assistant)

What you asked, what you kept, what you changed.