Practical Data Analysis Course / Chapter 1 — What to Decide Before You Analyze (lessons 1–4) / Lesson 1

Break a Question into Metric, Target, and Period

Time needed: about 5 min (estimate)

☆ Read later

You can try the opening of this lesson without an account.

How this course works

This course is a practical introduction to data analysis for people who've already learned Python and SQL.

It doesn't build models — instead it walks through framing a question → pulling data with SQL → cleaning it up → presenting it → standard analyses → communicating results.

The material stays fixed on a single fictional e-commerce shop's data, reused across all 30 lessons.

Sample data (used throughout)

Table Rows Contents customers 100 Customers (signup date, prefecture) products 8 Products (category, price) orders 181 Orders (163 completed, 18 canceled) order_items 369 Order line items events 234 Behavior log (view -> cart -> checkout -> purchase)

The sample code's lib/dataset.py fixes the random seed, so it produces the same data every time you build it.

Figures that appear in the text, like completed orders totaling ¥1,062,050, stay the same every run.

Verified with Python 3.14.2, SQLite 3.51.0, pandas 3.0.5, matplotlib 3.11.1, and pytest 9.1.1.

Terminal (setting up the sample code)

$ python3 -m venv .venv $ .venv/bin/pip install pandas matplotlib pytest $ scripts/test-lessons.sh # all 30 sessions $ scripts/test-lessons.sh 09 24 # just the specified sessions

"How's revenue doing?" can't be measured as-is

"How's revenue doing?" is a common question, but you can't act on it as stated.

That's because what to measure (the metric), what data to measure it against (the target), and what time range (the period) haven't been decided.

Once these three are in place, the question becomes something you can measure — and translate directly into SQL.

Three parts of breaking down a question

Metric What to measure? Sales / order count / number of buyers... Scope Which data? Completed orders only? Including cancellations? A specific category? Period From when to when? This month / month-over-month / last 6 months...

Checking measurability with a function

A function that checks whether the three parts are all in place, along with an example that turns a vague question into a measurable one.

It uses all() to check that metric, target, and period are all filled in.

It only needs the standard library, so you can run it right where you are.

Try removing a key and see how the result changes.

editor.py

Tab indents. To leave the editor, press Esc, then Tab.

Create a free account to keep reading

With an account you can read the rest of this lesson, take the quiz, and read every free lesson in this course. Lessons you answer correctly are recorded as complete.

Report a problem with this lesson

Log in to send a report.

Keyboard shortcuts

Keys available in a lesson
KeyAction
[ or Alt + ←Go to the previous lesson
] or Alt + →Go to the next lesson
?Open this list
EscClose this list

The keys do not work while the cursor is in a code editor or an input field.