Sub topic 15
Summarizing the analysis for the next reader
This chapter assumes you have followed the earlier chapters. You should have a notebook with a setup cell, a cleaning function, labeled plots, and a findings log. You should also know basic pandas.
Why a summary matters
A reader who opens your notebook rarely wants to scroll through 80 cells to learn what you found. A short summary at the top answers three questions: what was asked, what was found, and what to trust. You write it last, but it goes first.
What the summary contains
Keep it to one screen. Use these parts:
- Question: the goal you framed at the start.
- Data: the source, the date range, and the row count before and after cleaning.
- Findings: three to five statements, each with a number and a pointer to the cell or section that shows it.
- Caveats: what the data cannot tell you, such as missing regions or dropped rows.
- Open questions and next steps: what you would check next.
# Order amounts: exploratory analysis
**Question:** Do order amounts differ by region, and are a few large orders skewing the average?
**Data:** `data/raw/orders.csv`, 10,000 rows. 9,412 rows remain after `clean_orders` (see Section 3).
## Findings
1. Amounts are right-skewed: mean 54.20, median 31.80 (Section 5).
2. The `north` region has the highest median amount (Section 6).
## Caveats
- 4% of rows were dropped for missing or negative amounts.
## Open questions
- Do the large orders come from a few customers?Keep numbers from going stale
A number typed by hand into markdown goes out of date when the data or the cleaning rules change. Compute the figures in a code cell, then copy them into the summary. Do this after your final restart and run all.
import pandas as pd
df_raw = pd.DataFrame({"amount": [10.0, 20.0, None, 500.0, -5.0, 30.0]})
df = df_raw[df_raw["amount"].notna() & (df_raw["amount"] >= 0)]
summary = {
"rows_raw": len(df_raw),
"rows_clean": len(df),
"dropped_pct": round((1 - len(df) / len(df_raw)) * 100, 1),
"mean": round(df["amount"].mean(), 1),
"median": round(df["amount"].median(), 1),
}
print(summary)This prints {'rows_raw': 6, 'rows_clean': 4, 'dropped_pct': 33.3, 'mean': 140.0, 'median': 25.0}. The gap between mean and median is the kind of fact that belongs in a finding.
The order of the final steps
Write the summary only after the notebook runs cleanly from top to bottom. Otherwise the numbers you quote may come from hidden state.
Common errors
- Claims without evidence. Every finding should name the section that supports it.
- Hiding caveats. Dropped rows, imputed values, and small groups change how far a reader can trust a finding. State them.
- Stating hypotheses as facts. Write "may be driven by" when you have only seen a pattern. Say so if you have not tested it.
- Using internal shorthand. Write for someone who was not in your session.
A quick check before sending
- Does the first screen state the question and the main findings?
- Does each number match the output of a cell that has just been run?
- Are the caveats and open questions written down?
- Does the notebook pass restart and run all?
Exercise
You finish your analysis and write the summary at the top. Then you change a cleaning rule so that fewer rows are dropped. What should you do before handing the notebook off?
Show answer
Restart the kernel and run all cells, then recompute the figures and update the summary. The row counts, the dropped percentage, and any statistic that depends on the cleaned data may have changed. Also check that each finding still holds.