Sub topic 1
Start with questions, not code
An exploratory data analysis (EDA) is an open-ended look at a dataset to learn what it contains and what it can support. Without a stated purpose, it turns into a long run of df.head(), df.describe(), and plots that nobody can reread. This chapter covers the step that comes before any analysis code: writing down what you want to learn, and why.
Prerequisites
This chapter assumes you have:
- Basic Python: functions, imports, and f-strings.
- Familiarity with pandas DataFrames and basic indexing.
- Experience running cells in Jupyter or a similar notebook environment.
- Introductory statistics: mean, median, distribution, and correlation.
The examples use a hypothetical orders.csv file with the columns order_date, region, and amount. Later chapters load and clean this file.
Why questions come first
A dataset can be sliced in thousands of ways. If you open a notebook with no question, you pick slices by curiosity or habit. Three problems follow:
- No stopping point. Without a question, nothing tells you when the analysis is done.
- No way to judge relevance. You can't tell which of 40 plots matter, so the reader has to guess.
- More false patterns. The more slices you try without a plan, the more likely one looks interesting by chance. The pitfalls chapter returns to this.
Questions fix all three. A finished question is answered, or it is marked as unanswerable with the reason. Each plot either serves a question or gets cut.
From a decision to a question
Questions rarely start in the notebook. They start with someone who has to decide something. Work backward from that person.
- Name the decision or audience. For example: "The sales lead is deciding where to focus next quarter's regional campaigns."
- State the goal in one sentence. For example: "Understand how order value varies across regions and over time."
- Break the goal into specific questions. Each should be answerable with the data you have.
- Note what would change the plan. For example: "If one region has too few orders to compare, we say so instead of ranking it."
Compare a vague prompt with a usable one:
| Vague | Specific and answerable |
|---|---|
| "Explore the orders data." | "How skewed are order amounts, and is the mean a fair summary?" |
| "Look at regions." | "Do median order amounts differ between regions?" |
| "Check trends." | "Did the median order amount change from month to month in the last year?" |
A good question names the variables involved, says what kind of answer it expects (a distribution, a comparison, a trend), and can be wrong.
Exploratory does not mean unplanned
EDA is exploratory because you don't know the answers yet. It does not mean you don't know what you are asking. You can still follow surprises. When you do, write the new question down before chasing it, so the notebook shows why that section exists.
Check that the data can answer the questions
A question is only useful if the data can address it. Before writing analysis code, list the columns each question needs and compare that list with what the file contains. This check can fail early, which is the point.
import pandas as pd
QUESTIONS = {
"Q1": {
"text": "How skewed are order amounts?",
"needs": ["amount"],
},
"Q2": {
"text": "Do median order amounts differ between regions?",
"needs": ["region", "amount"],
},
"Q3": {
"text": "Did the median order amount change month to month?",
"needs": ["order_date", "amount"],
},
"Q4": {
"text": "Do returning customers spend more per order?",
"needs": ["customer_id", "amount"],
},
}
def check_coverage(df, questions):
rows = []
for qid, q in questions.items():
missing = [col for col in q["needs"] if col not in df.columns]
rows.append({
"id": qid,
"question": q["text"],
"answerable": not missing,
"missing_columns": ", ".join(missing),
})
return pd.DataFrame(rows)
# A tiny stand-in for the real file, so this cell runs on its own.
df_demo = pd.DataFrame({
"order_date": pd.to_datetime(["2025-01-03", "2025-01-04"]),
"region": ["north", "south"],
"amount": [20.0, 35.5],
})
print(check_coverage(df_demo, QUESTIONS).to_string(index=False))Q1 to Q3 are answerable. Q4 reports customer_id as missing. You now have three choices: drop Q4, find a data source that has customer IDs, or keep Q4 on the list marked "blocked". Each is fine. Discovering the gap after two hours of plotting is not.
Column presence is only the first filter. Later chapters cover the harder checks, such as whether a column is mostly missing or holds implausible values.
Put the questions at the top of the notebook
The questions belong in the notebook, in the first markdown cell, where every later reader sees them. A short template is enough:
# Orders EDA: how order value varies by region and time
**Audience and decision:** Sales lead, choosing regions for next quarter's campaigns.
**Goal:** Understand how order value varies across regions and over time.
## Questions
1. Q1. How skewed are order amounts, and is the mean a fair summary?
2. Q2. Do median order amounts differ between regions?
3. Q3. Did the median order amount change month to month in the last year?
4. Q4. (Blocked) Do returning customers spend more? Needs `customer_id`.
## Out of scope
- Forecasting future revenue.
- Product-level analysis (no product column in this file).
## Status
Last updated: see the findings log at the end of the notebook.Two parts of this template are easy to skip and worth keeping.
- Out of scope. Naming what you won't do protects you from scope creep. It also tells the reader that a missing analysis was a choice, not an oversight.
- Blocked questions. Keeping an unanswerable question visible, with the reason, is more honest than deleting it. The next person may have access to the missing data.
How questions shape the rest of the notebook
Each question maps to a place in the notebook. This mapping is what keeps the notebook readable as it grows.
In practice:
- Question Q1 becomes a section of univariate checks on
amount. - Q2 becomes a section comparing
amountacrossregion. - Q3 becomes a section grouping by month.
- Each section ends with a finding that points back to its question ID.
Using stable IDs such as Q1 and Q2 in section headings and findings lets a reader jump from an answer to the question that prompted it. The findings chapter builds on this.
Common mistakes at this stage
- Questions that are really tasks. "Clean the data" is a task. A question is something the data answers. Cleaning supports the questions but isn't one.
- Questions that can't fail. "What does the data look like?" is always satisfied. Prefer questions where a result could surprise you.
- Too many questions. A list of 25 is a sign the goal is unclear. Aim for three to seven per notebook, and split larger efforts into several notebooks.
- Writing the questions after the analysis. This produces questions that conveniently match the results you already have. Write them first, and edit them openly if they change.
- Skipping the audience. The same data supports different questions for a finance analyst and a campaign manager. If you can't name who reads the result, the goal isn't settled.
What to carry forward
By the end of this step you should have:
- One sentence naming the decision and audience.
- A numbered list of specific questions, each naming its variables.
- A coverage check showing which questions the data can address.
- An out-of-scope list and a list of blocked questions.
The next chapter turns this into a notebook layout, with sections that follow the order of your questions.
Exercise
You are given a file tickets.csv with columns ticket_id, opened_at, closed_at, category, and priority. A support manager wants to know "how the team is doing." Write a one-sentence goal and three specific questions that name their variables. Then say which question you would mark as blocked if the manager also wanted to know how satisfied customers are.
Show answer
Goal: "Understand how quickly tickets are resolved and whether resolution time differs by category and priority, so the manager can decide where to add staff." Questions: (1) How is resolution time (closed_at minus opened_at) distributed, and is the mean a fair summary? (2) Does median resolution time differ between category values? (3) Do high-priority tickets close faster than low-priority ones? A satisfaction question, such as "Which categories have the lowest customer satisfaction?", would be blocked because the file has no satisfaction or survey column. Mark it blocked and note that a survey data source is needed.
Exercise
Extend the QUESTIONS dictionary in this chapter with a fifth question, "Is the number of orders per region balanced?", and say which columns it needs. Would check_coverage mark it answerable on df_demo?
Show answer
Add "Q5": {"text": "Is the number of orders per region balanced?", "needs": ["region"]}. The check reports Q5 as answerable on df_demo, because region is present. This shows the limit of the check. It only confirms the column exists, not that df_demo has enough rows per region to answer the question, which later data-quality and first-look steps examine.