The question
Give the morning team two views of the same eligible orders: drink frequency and price distribution.
df Two-panel reportYour inputs
df
One row is one café order. Prices are already numeric or missing; drink labels need consistent spacing and case.
Field meanings and units
order_id- Order or order-line identifier, as defined by this brief.
drink- Recorded drink label.
size- Recorded serving size.
price- Price in dollars; unparseable text needs the stated policy.
tip- Tip in dollars.
shift- AM or PM service period.
date- Calendar date supplied as YYYY-MM-DD text unless the task states it is invalid.
order_id | drink | size | price | tip | shift | date |
|---|---|---|---|---|---|---|
| C001 | " Latte " | Small | 4.5 | 0 | AM | 2026-04-01 |
| C002 | tea | Large | 2.8 | 1 | PM | 2026-04-01 |
| C003 | LATTE | Small | 4.5 | 0.5 | AM | 2026-04-02 |
| C004 | " Mocha" | Large | 5.2 | None | AM | 2026-04-02 |
| C005 | " Latte " | Small | 4.5 | 0 | PM | 2026-04-03 |
View all 20 rows
order_id | drink | size | price | tip | shift | date |
|---|---|---|---|---|---|---|
| C001 | " Latte " | Small | 4.5 | 0 | AM | 2026-04-01 |
| C002 | tea | Large | 2.8 | 1 | PM | 2026-04-01 |
| C003 | LATTE | Small | 4.5 | 0.5 | AM | 2026-04-02 |
| C004 | " Mocha" | Large | 5.2 | None | AM | 2026-04-02 |
| C005 | " Latte " | Small | 4.5 | 0 | PM | 2026-04-03 |
| C006 | tea | Large | None | 1 | AM | 2026-04-03 |
| C007 | LATTE | Small | 4.5 | 0.5 | AM | 2026-04-04 |
| C008 | " Mocha" | Large | 5.2 | None | PM | 2026-04-04 |
| C009 | " Latte " | Small | 4.5 | 0 | AM | 2026-04-05 |
| C010 | tea | Large | 2.8 | 1 | AM | 2026-04-05 |
| C011 | LATTE | Small | 4.5 | 0.5 | PM | 2026-04-06 |
| C012 | " Mocha" | Large | 5.2 | None | AM | 2026-04-06 |
| C013 | " Latte " | Small | 4.5 | 0 | AM | 2026-04-07 |
| C014 | tea | Large | 2.8 | 1 | PM | 2026-04-07 |
| C015 | LATTE | Small | 4.5 | 0.5 | AM | 2026-04-08 |
| C016 | " Mocha" | Large | 5.2 | None | AM | 2026-04-08 |
| C017 | " Latte " | Small | 4.5 | 0 | PM | 2026-04-09 |
| C018 | tea | Large | 2.8 | 1 | AM | 2026-04-09 |
| C019 | LATTE | Small | 4.5 | 0.5 | AM | 2026-04-10 |
| C020 | " Mocha" | Large | 5.2 | None | PM | 2026-04-10 |
The editable setup in Your Python creates these inputs when you run it.
Give the morning team two views of the same eligible orders: drink frequency and price distribution.
populationDataFramecountsSeriesfigFigureDeliverables
Make the outputs listed below. Use each name exactly as shown. Then choose Check answer.
Python name key
Teal outlines name table columns. Violet left rules name Python objects. Dotted rules mark syntax, functions and parameters. Use each name exactly as shown.
Words in this task
- numeric
- a number, rather than text
- Eligible morning ordersOutput
populationDataFrame- Create
populationas AM orders with known numericprice; trim and lowercasedrink. - Keep other fields and source order.
- Create
- Drink frequenciesOutput
countsSeries- Store the number of orders for each
drinkinpopulationincounts.
- Store the number of orders for each
- FigureOutput
figFigure- Create
figwith two panels: bars comparingdrinkcounts, thenpricefrequencies across at least two contiguous numeric intervals. - Both frequency
axesmust start at zero. - Both panels must use
population. - Title and label both views
- Display the figure.
Panel 1: Identify Drink and Orders on the appropriate axes; extra wording is welcome. Panel 2: Identify Price (dollars) and Orders on the appropriate axes; extra wording is welcome.
- Create
Data policy Keep all supplied source tables unchanged. Work on separate outputs.
Help Hints & explained solution
Choose the amount of help you need. Opening one hint does not reveal the others.
Hint 1 — Think
Would two different populations make the panels tell a consistent story?
Hint 2 — Tools
Boolean selection, string accessors, value_counts(), subplots(), bar() and hist()
Revisit: Clean text · Combine conditions · Multiple subplots · Histogram · Count categories
Hint 3 — Approach
Define one eligible population; use it for both category counts and the price distribution in a single two-panel figure.
Explained solution
Add these lines below # Your work in the editor. The supplied input setup is already there.
population = df[(df['shift'] == 'AM') & df.price.notna()].copy()
population['drink'] = population.drink.str.strip().str.lower()
counts = population.drink.value_counts()
fig, axes = plt.subplots(1, 2, figsize=(9, 4))
axes[0].bar(counts.index, counts.values)
axes[0].set(title='Morning drink demand', xlabel='Drink', ylabel='Orders')
axes[1].hist(population.price, bins=4)
axes[1].set(title='Morning order prices', xlabel='Price (dollars)', ylabel='Orders')
fig.tight_layout()
plt.show()View supplied setup
This code is already at the top of the editor.
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Supplied input: df (20 rows)
df = pd.DataFrame(
[
('C001', ' Latte ', 'Small', 4.5, 0, 'AM', '2026-04-01'),
('C002', 'tea', 'Large', 2.8, 1, 'PM', '2026-04-01'),
('C003', 'LATTE', 'Small', 4.5, 0.5, 'AM', '2026-04-02'),
('C004', ' Mocha', 'Large', 5.2, None, 'AM', '2026-04-02'),
('C005', ' Latte ', 'Small', 4.5, 0, 'PM', '2026-04-03'),
('C006', 'tea', 'Large', None, 1, 'AM', '2026-04-03'),
('C007', 'LATTE', 'Small', 4.5, 0.5, 'AM', '2026-04-04'),
('C008', ' Mocha', 'Large', 5.2, None, 'PM', '2026-04-04'),
('C009', ' Latte ', 'Small', 4.5, 0, 'AM', '2026-04-05'),
('C010', 'tea', 'Large', 2.8, 1, 'AM', '2026-04-05'),
('C011', 'LATTE', 'Small', 4.5, 0.5, 'PM', '2026-04-06'),
('C012', ' Mocha', 'Large', 5.2, None, 'AM', '2026-04-06'),
('C013', ' Latte ', 'Small', 4.5, 0, 'AM', '2026-04-07'),
('C014', 'tea', 'Large', 2.8, 1, 'PM', '2026-04-07'),
('C015', 'LATTE', 'Small', 4.5, 0.5, 'AM', '2026-04-08'),
('C016', ' Mocha', 'Large', 5.2, None, 'AM', '2026-04-08'),
('C017', ' Latte ', 'Small', 4.5, 0, 'PM', '2026-04-09'),
('C018', 'tea', 'Large', 2.8, 1, 'AM', '2026-04-09'),
('C019', 'LATTE', 'Small', 4.5, 0.5, 'AM', '2026-04-10'),
('C020', ' Mocha', 'Large', 5.2, None, 'PM', '2026-04-10'),
],
columns=['order_id', 'drink', 'size', 'price', 'tip', 'shift', 'date'],
)Why these steps exist
- A single eligible population keeps the category and price views comparable.
- The first view counts drinks; the second counts observations within numeric price intervals. They answer different parts of the same brief.
Another valid approach
You may use either plotting library for either panel, but both panels must use the one declared population.