Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Data Foundations

← All challenges
VC01 · Café / orders · ~10–15 min

Which café category is busiest?

text quality · frequencies · communication

Demand comparison

The question

Help the café team compare demand for each drink after normalising inconsistent labels.

df Demand comparison

Your inputs

df

One row is one café order. Spaces and letter case in drink labels are inconsistent; every order belongs in this comparison.

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.
df · first 5 of 20 rows
order_iddrinksizepricetipshiftdate
C001" Latte "Small4.50AM2026-04-01
C002teaLarge2.81PM2026-04-01
C003LATTESmall4.50.5AM2026-04-02
C004" Mocha"Large5.2NoneAM2026-04-02
C005" Latte "Small4.50PM2026-04-03
View all 20 rows
df · complete input
order_iddrinksizepricetipshiftdate
C001" Latte "Small4.50AM2026-04-01
C002teaLarge2.81PM2026-04-01
C003LATTESmall4.50.5AM2026-04-02
C004" Mocha"Large5.2NoneAM2026-04-02
C005" Latte "Small4.50PM2026-04-03
C006teaLarge2.81AM2026-04-03
C007LATTESmall4.50.5AM2026-04-04
C008" Mocha"Large5.2NonePM2026-04-04
C009" Latte "Small4.50AM2026-04-05
C010teaLarge2.81AM2026-04-05
C011LATTESmall4.50.5PM2026-04-06
C012" Mocha"Large5.2NoneAM2026-04-06
C013" Latte "Small4.50AM2026-04-07
C014teaLarge2.81PM2026-04-07
C015LATTESmall4.50.5AM2026-04-08
C016" Mocha"Large5.2NoneAM2026-04-08
C017" Latte "Small4.50PM2026-04-09
C018teaLarge2.81AM2026-04-09
C019LATTESmall4.50.5AM2026-04-10
C020" Mocha"Large5.2NonePM2026-04-10

The editable setup in Your Python creates these inputs when you run it.

Your task · Which café category is busiest?

Help the café team compare demand for each drink after normalising inconsistent labels.

countsSeriesfigFigure

Deliverables

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.

  1. Drink countsOutputcountsSeries
    1. Store the number of orders for each drink after trimming and lowercasing its label in counts.
    2. Keep df.
  2. FigureOutputfigFigure
    1. Create fig comparing every category count.
    2. Choose labelled bars or individual points; either orientation is valid.
    3. Bars must start at zero.
    4. Add a meaningful title and measure labels
    5. Display the figure.

    Identify Drink and Orders on the appropriate axes; extra wording is welcome.

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

Does each spelling represent a different drink or just different formatting?

Hint 2 — Tools

String accessors, value_counts(), Axes.bar() or Axes.barh(), or Axes.scatter() for a labelled point comparison

Revisit: Clean text · Count categories · Count categories · Finish a chart properly · Scatter plot

Hint 3 — Approach

Standardise labels, count each drink and show all category counts on a zero-based quantitative axis.

Explained solution

Add these lines below # Your work in the editor. The supplied input setup is already there.

work = df.copy()
work['drink'] = work.drink.str.strip().str.lower()
counts = work.drink.value_counts()
fig, ax = plt.subplots()
ax.bar(counts.index, counts.values)
ax.set(title='Café drink demand', xlabel='Drink', 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', 2.8, 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

  • Normalising labels prevents one drink from being split into several categories.
  • Category counts are lengths on a common zero-based scale; orientation does not change the evidence.

Another valid approach

Labelled individual points are also valid for comparing these summaries. Vertical and horizontal orientations are accepted; bars must use a zero baseline.

Tab: indent · Shift+Tab: outdent · Esc, then Tab: leave editor

Edit Python. Control or Command plus Enter runs it. Tab indents by four spaces. Shift plus Tab outdents. Press Escape, then Tab or Shift plus Tab to leave the editor.

Each run executes all editor code in a fresh Python session. Named outputs appear below when you run. Display charts with plt.show().

Python starts when you open a lesson.

Output

Run your code to see what Python returns.