Data cleaning
Data cleaning is the process of finding errors, gaps and duplicates in a dataset and correcting, flagging or removing them before the data is used. Statistical agencies call the detection and treatment of errors data editing.
What it is
Data cleaning is the work of detecting and treating errors, missing values and duplicates in a dataset so that it is fit for analysis or reporting. The European Commission statistics portal describes statistical data editing as the activities aimed at finding and fixing errors in collected data.
The work follows a sequence:
- Profiling: counts, ranges, distributions and frequency tables show what the data contains.
- Standardising: formats, units, currency codes and date conventions are made uniform.
- Deduplication: records that describe the same real-world item are matched and merged or removed.
- Missing values: a gap is flagged, left as it is, or filled by imputation, which means estimating a replacement value.
- Outliers: extreme values are compared with the source, then corrected or kept as genuine.
The same portal separates micro editing, which checks each record, from macro editing, which checks aggregated figures for suspicious values. Selective editing directs manual effort to the errors that most affect the final results.
The OECD glossary defines a deterministic edit as a check whose violation indicates an error with a probability of one, for example a recorded age of 5 combined with the status of mother. Edits with a lower probability only mark a value as suspicious.
The Eurostat recommended practices state that replacing missing values by zero is neither an acceptable imputation procedure nor an acceptable alternative to flagging them.
Why it matters
Analysis, models and reports inherit every error in their input. A duplicate counts a customer twice, and a misplaced decimal point distorts an average.
Cleaning turns a raw extract into a dataset whose limits are known. Each change is logged, so that a reader can trace a published figure back to the original value.
Worked example
Illustrative numbers. An extract holds 1,000 customer records.
- 60 records repeat the same identifier and date. They are removed, leaving 940.
- 25 records show a birth date after the application date. This breaks a deterministic edit, so they are returned to the source for correction.
- 40 records have no country. They are flagged as unknown and not filled.
- 3 balances are 100 times the typical value. Two are found to contain an extra zero typed in error and are corrected. One is genuine and kept.
The cleaned file holds 940 records, with 28 corrections or returns and 40 flagged gaps, all listed in a change log.
Assumptions
- A trusted source or rule exists against which a value can be judged wrong.
- The original data is kept, so that every change can be reversed.
- Missing values are treated according to why they are missing, which affects whether imputation is sound.
Who uses it
- Data analysts and data scientists clean extracts before analysis and modelling.
- Master data and reference data specialists correct and merge records in shared data sets.
- Regulatory reporting analysts clean source data before it enters a return.
- Business intelligence analysts correct data feeding dashboards.
Common confusions
- Cleaning versus validation: validation tests data against rules and reports failures, while cleaning treats the failures.
- Cleaning versus data quality management: cleaning fixes a given dataset, while data quality management also addresses why errors arise at the source.
- Outliers versus errors: an extreme value can be genuine, so it is checked before it is removed.
- Imputation versus correction: imputation estimates a plausible value, and the estimate is marked as such.