Sub topic 4
Cleaning and exploring the results
This chapter assumes you can read a spreadsheet or a short pandas script and that you know what a percentage and an average are. It also assumes you have a raw export from a survey tool. You will turn that export into a dataset you can defend, then look through it for findings without fooling yourself.
Cleaning and exploring come before you choose an angle. A finding built on duplicate rows, rushed answers, or a tiny subgroup can fall apart when a journalist asks one question. Each cleaning step you take also has to be described later in your methodology note, so record every decision as you make it.
Start with an untouched copy
Before you change anything, save the raw export as a read-only file. Do all your work on a copy. If someone questions a number, you can rebuild it from the raw file and show exactly what you removed and why.
Keep three files together:
- The raw export, never edited.
- A cleaning log that lists each rule, how many respondents it affected, and the date.
- The cleaned dataset, with a flag column for each rule, so removals can be reviewed rather than silently deleted.
Also check the data dictionary. This is the list of what each column means, what each code stands for, and which questions allow several answers. A value of 5 might mean "very worried" on one question and "not applicable" on another. Confirm the coding for every question you plan to report before you calculate anything.
The cleaning pipeline
Work in a fixed order so your counts reconcile at each step.
Duplicates and ineligible respondents
Duplicates appear when someone submits twice or a panel provider sends a record again. Match on a respondent ID, not on the answers, because two real people can give identical answers. Then check eligibility. If the survey was meant for adults who manage a household budget, remove people who failed the screening question but were let through by a routing error.
Speeders and straightliners
A speeder finishes far faster than a person could read the questions. A common rule flags anyone under one-third of the median completion time. A straightliner gives the same answer to every item in a grid of rating questions. Neither pattern proves bad faith. Someone may really hold the same opinion on every item. So use these flags as signals, and consider removing a respondent only when the evidence is strong, such as failing both checks. Whatever rule you choose, apply it to everyone and write it down.
Straightlining only means something on a grid with enough items, usually five or more, and where the items are not all worded in the same direction. The example below uses four items to keep the data small.
Missing answers and "don't know"
Treat these two cases separately.
- Missing means the person skipped the question or never saw it. Do not fill in a guess. Report percentages out of those who answered, and state that base.
- "Don't know" or "prefer not to say" is an answer. If 18% say "don't know," that may itself be a finding. Decide whether your percentages include them in the base. The choice changes the headline number, so apply it consistently and disclose it.
Recoding
Recoding means turning raw codes into the groups you will report, such as collapsing a 1–5 agreement scale into "agree" (4–5), "neutral" (3), and "disagree" (1–2). Fix the cut points before you look at results. If you pick them after seeing which version looks most dramatic, you are choosing the story before checking the data.
A worked example
This script uses a small made-up dataset so it runs as shown. Real surveys have hundreds or thousands of rows, but the steps are the same.
import pandas as pd
raw = pd.DataFrame({
"id": [1, 2, 3, 3, 4, 5, 6, 7],
"duration_sec": [310, 295, 410, 410, 45, 380, 360, 290],
"age_group": ["18-34", "35-54", "55+", "55+", "18-34", "35-54", "55+", None],
"worry": [4, 2, 5, 5, 3, 3, 4, 2], # 1-5 scale, 5 = very worried
"g1": [4, 2, 5, 5, 3, 3, 4, 2],
"g2": [3, 2, 4, 4, 3, 2, 4, 3],
"g3": [5, 3, 4, 4, 3, 4, 4, 2],
"g4": [2, 4, 5, 5, 3, 3, 4, 3],
})
grid = ["g1", "g2", "g3", "g4"]
# 1. Remove duplicate submissions by respondent ID.
df = raw.drop_duplicates(subset="id").copy()
# 2. Flag speeders (under one-third of the median time) and straightliners.
cutoff = df["duration_sec"].median() / 3
df["speeder"] = df["duration_sec"] < cutoff
df["straightliner"] = df[grid].nunique(axis=1) == 1
# 3. Keep respondents who pass both checks.
clean = df[~(df["speeder"] | df["straightliner"])].copy()
# 4. Recode: "worried" means 4 or 5 on the 5-point scale.
clean["worried"] = clean["worry"] >= 4
print(len(raw), len(df), len(clean)) # 8 7 5
print(round(clean["worried"].mean() * 100, 1)) # 40.0
print(clean["age_group"].isna().sum()) # 1
print(clean.groupby("age_group", dropna=False)["worried"].agg(["count", "mean"]))The first print line shows the log you should keep: 8 rows received, 7 after removing a duplicate, 5 after removing one speeder and one straightliner. The last line shows each age group's size and the share who are worried. Passing dropna=False keeps the respondent with no age group visible as its own row. If you dropped that row by default, the group sizes would no longer add up to your total.
Exploring without fooling yourself
Exploration means looking through the data for patterns. It is where most mistakes about statistics begin, so follow a routine.
1. Read the toplines first
A topline is the overall result for each question, such as "40% are worried." Check each one against what you expected. A surprising topline is either a story or a coding error, and you need to know which before you go further.
2. Cross-tabulate
A crosstab splits one question by another, such as worry by age group, region, or income band. This is where angles usually appear. For each cell, note two things: the percentage and the number of people behind it.
3. Check the base size of every group
A subgroup with 40 respondents has a much wider margin of error than the full sample of 1,000. A group of 12 cannot support any public claim. A practical rule is to report subgroup figures only when the base is at least 100, or to label smaller ones "indicative only." The next chapters on margin of error and statistical claims cover how to quantify this.
4. Check for a lopsided sample
Compare your sample's makeup to what you know about the population. If 70% of respondents are over 55 but the population is 30% over 55, your unweighted topline is skewed. Weighting corrects this, and you should apply the weights in every table you publish. Mixing weighted and unweighted figures is a common error that produces numbers that do not match across your own materials.
5. Beware of the many-comparisons problem
If you compare 20 questions across 6 groups, you run 120 comparisons. By chance alone, several will look like differences even if none exist. When you find a striking difference in a place you were not specifically looking, treat it as a lead to check rather than a result. Look for support from related questions. If people who say they are worried about prices also report cutting back on spending, the pattern holds together. A lone odd cell does not.
6. Look at the full distribution
An average can hide the real pattern. If the mean rating is 3.0 on a 5-point scale, that could mean everyone is neutral or that half are at 1 and half at 5. Look at the counts for each answer option before you describe the group in one number.
Common errors
| Problem | What it looks like | What to do |
|---|---|---|
| Silent deletion | Row counts drop with no record | Keep flag columns and a cleaning log |
| Changing the base | "Don't know" is included in one table and excluded in another | Fix one base rule and state it |
| Inconsistent weights | Charts and text show different percentages | Apply the same weights everywhere |
| Tiny subgroups | A headline built on 15 respondents | Set a minimum base and label smaller groups |
| Post-hoc recoding | Cut points chosen after seeing results | Define the groups before looking at outcomes |
| Reading codes wrong | A reversed scale flips the finding | Check every question against the data dictionary |
What to hand to the next step
When you finish, you should have:
- A cleaned file with weights applied and flags preserved.
- A cleaning log with a count after each step.
- A shortlist of two to four candidate findings, each with its percentage, base size, and the question wording behind it.
The next chapter takes that shortlist and asks which finding is actually news. The cleaning log goes straight into your methodology note later, so keep it accurate now.
Exercise
A survey of 1,200 adults has 1,150 left after cleaning. In the crosstab, 62% of the 38 respondents aged 18–24 say they support a new policy, against 45% overall. A colleague wants the headline "Young adults overwhelmingly back the policy." Name two problems with this plan and one thing you would do before using it.
Show answer
First, the base is only 38, so the 62% has a very wide margin of error and the gap from 45% may not be real. Second, this difference was probably found by looking across many subgroups, so it may be a chance result. Before using it, check whether the pattern shows up in related questions or in a larger age band such as 18–34. Only report the finding if it holds up and the base is large enough, or else label it indicative.