Data Cleaning: A Practical Guide to Tidy Data
Data cleaning is the work of finding and fixing the mistakes, gaps and inconsistencies in a dataset so that it can be used with confidence. It sits at the start of almost every analysis, report or dashboard, and it is usually the part that takes the longest. The idea is simple: before you count, compare or chart anything, you make sure the underlying records say what they claim to say.
Raw data arrives messy for ordinary reasons. People type quickly, systems disagree about formats, records get merged from several sources, and fields that were optional in one place are mandatory in another. None of this is a failure of effort; it is simply what happens when information is collected by humans and machines at speed.
The problems you will meet
Most cleaning work falls into a handful of categories:
Read more
- Missing values, where a field is blank because it was unknown, not applicable, or never filled in.
- Duplicates, where the same record appears twice with small differences.
- Format inconsistencies, such as dates written in several conventions or names with stray spaces.
- Invalid entries, where a value falls outside the range that makes sense.
- Inconsistent categories, where one thing is spelled several ways or labelled by different synonyms.
- Structural problems, where a single column holds two pieces of information or one record is spread across several rows.
The main techniques
Cleaning usually follows a repeatable sequence. Profile the data first: look at how many rows you have, how many blanks each column contains, which values are most common and what the extremes look like. Profiling tells you where the problems are before you start changing anything.
Then standardise: unify date formats, trim whitespace, settle on one spelling for each category and one convention for numbers and units. Remove duplicates once you have defined what makes two records genuinely identical. Handle missing values deliberately, either by excluding them, filling them with a clearly documented rule, or flagging them so the rest of the analysis can treat them honestly.
Validation comes next. Simple rules, such as a date that cannot be in the future or a quantity that cannot be negative, catch errors that slip past visual checks. Where possible, automate the whole sequence so that it can be run again when fresh data arrives.
What beginners should know
Keep a copy of the original file untouched and work on a duplicate, so you can always go back. Document every change you make, even small ones, because you will forget and someone else may need to follow your reasoning. Clean one issue at a time and check the row count after each step, so you notice immediately if something went wrong.
Finally, remember that cleaning is not about making data look neat. Every change is an interpretation. When you decide that two spellings mean the same thing, or that a blank should be treated as zero, you are making a judgement about what the data represents. Make those judgements consciously, write them down, and your results will be far easier to trust.