Data Cleaning for Descriptive Statistics: A Practical Guide
Why Data Cleaning Matters
The five number summary, like all descriptive statistics, is only as reliable as the data it summarizes. A single misplaced decimal (entering 750 instead of 7.50) or an invalid entry ("N/A" in a numeric column) can distort results. Data cleaning — the process of detecting and correcting errors before analysis — is not optional; it is the foundation of trustworthy statistics.
Imagine calculating the five number summary for employee salaries and finding a maximum of $5,000,000. Before reporting this as a genuine outlier, verify whether it is a data entry error (perhaps $50,000 with extra zeros) or a legitimate executive salary.
Common Data Issues
- Typos and data entry errors: Transposed digits (54 → 45), extra zeros (500 → 5000), wrong sign (−12 instead of 12)
- Mixed formats: "15%", "0.15", and "15" in the same column all representing 15 percent
- Invalid entries: Text in numeric fields ("N/A", "pending", "#REF!"), dates parsed as numbers
- Duplicate records: The same observation counted twice inflates frequency and distorts quartiles
- Measurement errors: Instrument miscalibration producing systematically high or low readings
- Unit inconsistencies: Mixing kilograms and pounds, centimeters and inches in the same column
A Step-by-Step Cleaning Workflow
Before calculating any summary statistics, follow this sequence:
- Inspect the raw data: Scan for obvious problems — blank cells, text in numeric columns, extreme values
- Check data types: Ensure numeric columns contain only numbers. Convert text representations ("$1,200") to numeric values (1200)
- Remove or flag duplicates: Identify and handle repeated entries
- Standardize formats: Convert all values to the same unit and notation
- Handle missing values: Decide whether to exclude, impute, or flag them
- Validate ranges: Check that all values fall within plausible bounds (e.g., ages between 0 and 120, percentages between 0 and 100)
- Document changes: Record what was modified and why, preserving the original data separately
Golden Rule
Never modify the original dataset. Work on a copy and maintain a log of all changes. This ensures reproducibility and allows reverting if a cleaning decision turns out to be incorrect.
Using the Five Number Summary to Detect Errors
The five number summary itself serves as a diagnostic tool. After an initial calculation, check for red flags:
- Implausible Min or Max: A minimum temperature of −999°C or maximum age of 250 likely indicates sentinel values or data entry errors
- IQR of zero: All quartiles equal — the data may contain too many identical values or may not be properly parsed
- Extreme range relative to IQR: Range > 10 × IQR often signals outliers worth investigating
- Negative values in non-negative fields: Negative prices, negative counts, or negative durations point to sign errors
Data Cleaning in Spreadsheets
Common techniques for cleaning data in Excel or Google Sheets:
- Remove non-numeric characters: Use
=VALUE(SUBSTITUTE(SUBSTITUTE(A1,"$",""),",",""))to strip dollar signs and commas - Find duplicates: Conditional formatting → Highlight Duplicate Values, or use
=COUNTIF() - Validate range:
=IF(AND(A1>=0, A1<=100), A1, "CHECK")flags values outside 0–100 - Identify blanks:
=COUNTBLANK(A1:A100)counts empty cells - Sort and scan: Sorting by value places errors at the extremes where they are easy to spot
Data Cleaning in Python and R
For larger datasets, code-based cleaning is more efficient and reproducible:
# Python (pandas) import pandas as pd df = pd.read_csv("data.csv") # Check for non-numeric values df["score"] = pd.to_numeric(df["score"], errors="coerce") # converts errors to NaN # Remove duplicates df = df.drop_duplicates() # Flag out-of-range values df.loc[(df["age"] < 0) | (df["age"] > 120), "age"] = None # Check the result print(df["score"].describe())# R data <- read.csv("data.csv") # Convert to numeric (non-numeric becomes NA) data$score <- as.numeric(as.character(data$score)) # Remove duplicates data <- unique(data) # Flag out-of-range values data$age[data$age < 0 | data$age > 120] <- NA # Check the result summary(data$score)Coercion to NaN
Using pd.to_numeric(errors="coerce") in pandas or as.numeric() in R silently converts invalid entries to NaN/NA. Always check how many values were converted — a high count may indicate a systematic formatting issue rather than isolated errors.
Outliers vs. Errors: A Critical Distinction
Not every extreme value is an error. The five number summary and IQR method flag statistical outliers, but flagging is not the same as removing. The decision process:
- Verify the value: Check the original source. Is 250 a typo for 25, or a genuine measurement?
- Assess plausibility: Does the value make sense in context? A 250-pound person is plausible; a 250-foot person is not.
- Check for patterns: Multiple outliers from the same source or time period may indicate a systematic issue.
- Document the decision: Whether kept, removed, or corrected, record the rationale.
Impact of Uncleaned Data on Statistics
| Issue | Effect on Five Number Summary |
|---|---|
| Extra zero (50 → 500) | Inflates Max and possibly Q3; distorts IQR and range |
| Duplicate entries | Can shift quartiles and median; inflates apparent sample size |
| Text parsed as zero | Artificially lowers Min and Q1; creates false outliers |
| Mixed units | All five values become meaningless — the data is not comparable |
| Sentinel values (−999, 9999) | Extreme Min or Max; IQR may be unaffected if few sentinels exist |
Best Practices Summary
- Clean before calculating — never compute statistics on raw, unvalidated data
- Preserve the original dataset; work on copies
- Use the five number summary as a first diagnostic — implausible Min/Max values reveal errors quickly
- Document every cleaning decision for reproducibility
- Validate with domain knowledge — statistical tools flag anomalies, but context determines whether they are errors or genuine values
Verify Your Calculations
Use the free five number summary calculator to check your work.
Open CalculatorWritten by Oge Nwaozuzu
Statistics educator and data analyst. Creator of 5numbersummarycalculator.app.