Sub topic 15
Writing down findings and next questions
This chapter closes the exploration. You have loaded the Titanic CSV, checked missing values and duplicates, summarized columns, compared groups, plotted, and looked at correlations. Now you turn that work into a short written record that someone else, or you in three weeks, can read and trust.
It assumes you have finished the earlier chapters. You should be comfortable with groupby, agg, isna, and corr, and you should know why a group's count matters next to its mean.
Why write findings down
Exploration produces many outputs and few conclusions. A notebook full of tables is a log, not a result. If you don't write the conclusions down, three things tend to happen:
- You forget which numbers you checked and which you only glanced at.
- A surprising result gets remembered as a fact, without the caveat you noticed when you saw it.
- The next person repeats your work because they can't tell what is already known.
A written record also forces you to test each claim. A sentence like "women survived more often" is easy to say. Writing it with a number and a group size shows whether the evidence supports it.
The shape of a good finding
Each finding has four parts:
| Part | Question it answers | Example |
|---|---|---|
| Claim | What did you observe? | Women survived at a much higher rate than men. |
| Evidence | Which numbers, from which code? | `groupby("Sex")["Survived"].agg(["count", "mean"])` |
| Caveat | What could make this misleading? | Class and age differ between the sexes. This is a comparison, not a cause. |
| Next question | What would you check next? | Does the gap remain within each class? |
Keep the claim in plain words, and give group sizes next to every rate. A rate with no count can't be judged.
Separate three kinds of statements, because readers treat them differently:
- Observations: facts about this table, such as "Age is missing in about 20% of rows."
- Interpretations: explanations you suspect, such as "Missing Age may be more common in third class."
- Questions: things you have not checked yet.
Mixing these is the most common way an exploration turns into an overclaim.
From exploration to record
The record is the last step of a loop. Findings produce new questions, which send you back to the data.
Decide up front what "done" means. For a first pass, it is usually: the starting question has an answer you can state with its limits, and the open questions are written down.
Generating the numbers instead of typing them
Numbers copied by hand into notes go stale when the data or the code changes. A safer habit is to compute the figures in code and write them into the notes in the same step. The script below builds a short findings file from the data. It reuses the checks from earlier chapters.
from pathlib import Path
import pandas as pd
df = pd.read_csv("train.csv")
n_rows, n_cols = df.shape
overall = df["Survived"].mean()
age_missing = df["Age"].isna().mean() * 100
cabin_missing = df["Cabin"].isna().mean() * 100
duplicates = int(df.duplicated().sum())
by_sex = df.groupby("Sex")["Survived"].agg(["count", "mean"])
by_class_sex = df.groupby(["Pclass", "Sex"])["Survived"].agg(["count", "mean"])
lines = [
"# Titanic first pass: findings",
"",
"## Data",
f"- {n_rows} rows, {n_cols} columns, {duplicates} duplicate rows.",
f"- Age missing in {age_missing:.1f}% of rows; Cabin missing in {cabin_missing:.1f}%.",
"",
"## Findings",
f"- Overall survival rate: {overall:.1%}.",
]
for sex, row in by_sex.iterrows():
lines.append(f"- {sex}: {row['mean']:.1%} survived (n={int(row['count'])}).")
lines += ["", "## Survival by class and sex"]
for (pclass, sex), row in by_class_sex.iterrows():
lines.append(
f"- Class {pclass}, {sex}: {row['mean']:.1%} (n={int(row['count'])})."
)
lines += [
"",
"## Caveats",
"- Age is missing for a fifth of passengers; age-based results use only the rest.",
"- Group rates are descriptive. Differences may reflect class, age, or other factors.",
"",
"## Next questions",
"- Is missing Age related to class or survival?",
"- Does the sex gap remain after splitting by class and age group?",
]
Path("findings.md").write_text("\n".join(lines) + "\n", encoding="utf-8")
print("\n".join(lines))Two details are worth noticing. The sentence about Age missing "a fifth" is typed by hand, so check it against the computed percentage. Better, put the computed value into that line as well. Also, the n= figure sits beside every rate, as the finding format requires.
What to record for a first pass on Titanic
For this dataset, a reasonable set of findings looks like the list below. Your code should reproduce each number.
- Structure: 891 rows and 12 columns, with no duplicate rows.
- Missing data: Cabin is missing in most rows, Age in roughly a fifth, and Embarked in two rows.
- Outcome: about 38% of passengers in this file survived.
- Sex: the survival rate for women is far higher than for men.
- Class: survival falls from first to third class.
- Combination: the sex gap appears inside each class, but group sizes differ a lot. Few first-class women exist compared with third-class men, so compare counts before comparing rates.
- Correlation:
Pclasshas a negative correlation withSurvived, andFarea weaker positive one. Both are linear measures on columns that are partly redundant with each other.
Each of these needs its caveat attached. For instance, "survival falls with class" should carry the note that class also relates to age, sex, and where passengers were on the ship.
Handling missing data in the record
Say what you did with missing values, not only that they exist. A finding computed from Age covers only the passengers whose age is known. State that, and state the count. If you filled values in, name the method. If you dropped rows, say how many.
known_age = df["Age"].notna()
print("rows with Age:", int(known_age.sum()), "of", len(df))
print(df.loc[known_age].groupby("Sex")["Survived"].agg(["count", "mean"]))The output tells the reader how many rows stand behind the claim, which an unqualified table would hide.
Writing caveats that help
A caveat is useful when it names a specific risk and says what it affects. Compare these:
- Weak: "Results may be biased."
- Useful: "Age is missing for about 20% of passengers, so age-group rates exclude them. If missing ages are more common among those who died, the rates are off."
Common caveats for this kind of analysis:
- Small groups: a rate based on a handful of rows moves a lot if one row changes.
- Confounding: two factors tangled together, such as class and fare, so you can't say which one matters.
- Correlation: it measures linear association between numeric columns. It says nothing about cause, and it ignores non-numeric columns unless you encode them.
- One file:
train.csvis a sample from a larger passenger list. Treat rates as properties of this file.
Writing next questions
A next question is something you can check. Good ones name a column, a comparison, or a method. Vague ones ("understand survival better") give you nothing to run.
| Vague | Checkable |
|---|---|
| Look into age more | Compare survival across age groups within each class. |
| Is the data clean? | Are there fares of zero, and which rows have them? |
| Missing values | Is missing Age more common in a given class? |
| Modeling | Which columns would a baseline model use, and how would Cabin be handled? |
Rank the questions by how much each could change your conclusions. A question that could overturn a headline finding comes before one that adds detail.
A reusable template
Keep one structure for every exploration so notes stay comparable:
- Question and data source: what you wanted to know and which file, with its date or version.
- Data checks: shape, dtypes, missing values, duplicates, implausible values.
- Findings: claim, evidence, caveat, each with group sizes.
- Decisions made: what you filtered, filled, or dropped, and why.
- Open questions: ranked, checkable.
The "decisions made" section is easy to skip, and it matters most. Anyone rerunning your work needs to know that you excluded rows or created AgeGroup.
Exercise
Your notes say "First-class passengers survived at a higher rate than third-class passengers." Rewrite it as a complete finding using the four-part format. What do you need to compute first, and name one caveat and one next question.
Show answer
Compute df.groupby("Pclass")["Survived"].agg(["count", "mean"]). The claim then states both rates with their group sizes, for example "Class 1: 63% (n=216), class 3: 24% (n=491)". The evidence is that groupby call. A caveat: class is tied to sex and age, so the difference may partly reflect who traveled in each class, and it does not show that class caused survival. A next question: does the class gap remain within each sex and age group? Check with groupby(["Pclass", "Sex"]) and AgeGroup.
Exercise
A teammate reports that passengers with a recorded Cabin survived much more often than those without one, and concludes that having a cabin saved lives. Which caveats from this chapter apply, and what would you write instead?
Show answer
Cabin is missing in most rows, so the comparison is between a small recorded group and a large unrecorded group. The record of a cabin is probably tied to class, since first-class passengers are more likely to have one recorded, so class confounds the result. Finally, the comparison shows association only. A better statement: "Passengers with a recorded Cabin survived at a higher rate (include both rates and counts), but Cabin is mostly missing and likely reflects class. Next question: does the gap remain within each class?"