Data cleaning basics

Why real data is messy, the five problems you meet most often and how to fix each one before you count anything. With worked examples, a cleaning routine in eight steps, spreadsheet functions that help, common mistakes and a short quiz.

Guide45 minBachelor +2CC BY 4.0

What you will learn

  • Name the five most common problems in a data set
  • Choose a fix for each
  • Explain why cleaning comes before counting
  • Follow a cleaning routine and document what was changed
  • Use TRIM, LOWER and find and replace in a spreadsheet

A count is only as good as the rows behind it. If one customer appears three times, every average that includes them is wrong. Cleaning means finding these problems before you calculate.

Why it matters: a worked example

Litware's small online shop exports its orders for one day. The export has six rows:

Order

Customer

Amount (euros)

501

Greta Nilsson

30

502

David Lee

45

503

Emma Schulz

60

504

Ivan Petrov

90

504

Ivan Petrov

90

505

Julia Klein

75

Order 504 was exported twice. With the duplicate, the shop seems to have had 6 orders worth 390 euros, an average of 65 euros. In truth it had 5 orders worth 300 euros, an average of 60 euros. One extra row changed the revenue by 30 percent and the average by more than 8 percent. Nobody made a calculation mistake; the data was wrong before anyone started.

The five problems you meet most

Problem

Example

Fix

Duplicates

The same person entered twice

Choose a key column, remove repeats

Inconsistent spelling

Munich, München, munich

Agree on one form and replace the others

Extra spaces and capitals

" Anna@Example.com "

Trim spaces, compare in lower case

Missing values

An empty country field

Fill it from another source, or mark it unknown

Wrong types

12,5 stored as text

Convert it to a number your program understands

Duplicates

A duplicate is a second record for something that is already there. It is rarely identical: one row says "Fabrikam Inc.", the other "Fabrikam Inc". The key question is which column, or columns, identify a record. For one row per person, the email address is usually the best key. For one row per order, the order number. Matching on every column finds only exact copies.

Inconsistent spelling

The same thing written in different ways: Munich and München, "UK" and "United Kingdom", "n/a" and "none". A computer treats each spelling as a different value, so a count by city shows Munich twice. Agree on one form, write it down, and replace the others with find and replace.

Extra spaces and capitals

A space at the end of a value is invisible but makes "Hamburg " different from "Hamburg". Capitals do the same for "anna@" and "Anna@". Trim the spaces and, for values like email addresses, compare in lower case.

Missing values

An empty cell can mean "unknown", "not asked", "zero" or "not applicable". These are different things. Never fill an empty cell with 0 unless you know it really means zero: an empty "amount" filled with 0 pulls the average down. Fill gaps from a reliable source, or mark them clearly as unknown and leave them out of the calculation.

Wrong types

A number stored as text cannot be added up. This often happens when a file moves between countries: in Germany 12,5 means twelve and a half, while English-language software reads the comma as a separator and expects 12.5. Convert the column to numbers, and check a few values by hand afterwards.

Two more to watch

  • Impossible values. A customer aged 230, an order with −3 items, a delivery date before the order date. Check them against the original source. Do not just delete them.

  • Dates in different formats. 03/04/2026 is 3 April in the UK and 4 March in the US. Store dates in one clear format, such as 2026-04-03 (year, month, day, the international ISO 8601 standard).

Sort into groups

Which problem is it?

Duplicate

Inconsistent spelling

Missing value

Extra spaces or capitals

Wrong type

A cleaning routine in eight steps

  1. Keep a copy of the original. Clean a copy, never the only file.

  2. Look before you change anything. Sort each column, filter for empty cells, count the rows.

  3. Trim spaces and fix capitals.

  4. Make spellings and formats consistent: one spelling per city, one date format, numbers as numbers.

  5. Remove duplicates, after steps 3 and 4: two rows that differ only in a space are only found once the spaces are gone.

  6. Deal with missing and impossible values: fill, mark as unknown or check at the source.

  7. Write down what you changed, for example "removed 3 duplicates by email; replaced München with Munich in 2 rows".

  8. Count and calculate.

Worked example: a contact list

Before:

Name

Email

City

Anna Berger

anna.berger@northwind.example

Hamburg

anna berger

" Anna.Berger@Northwind.example "

Hamburg

Carla Mendes

carla.mendes@fabrikam.example

München

Carla Mendes

carla.mendes@fabrikam.example

Munich

Ben Okafor

ben.okafor@contoso.example

(empty)

Steps: trim the spaces and lower-case the email column (rows 1 and 2 now match); replace "München" with "Munich" (rows 3 and 4 now match); remove duplicates by email; mark Ben's city as unknown. After: 3 rows, one per person. The note says: "Trimmed and lower-cased emails, replaced München with Munich (1 row), removed 2 duplicates by email, 1 city unknown."

Spreadsheet functions that help

All common spreadsheet programs have these:

  • TRIM(A2) removes spaces at the start and end and turns double spaces into single ones.

  • LOWER(A2) turns text into lower case; PROPER(A2) capitalises each word, useful for names.

  • Find and replace fixes one spelling in a whole column at once.

  • A filter shows only the empty cells, or only one value, so you can check them.

  • Most programs also have a remove duplicates command. Check which columns it compares before you use it.

Put the function in a new column, check the result, then copy it over the old values.

Common mistakes

  • Cleaning the only copy. If something goes wrong, the original is gone.

  • Removing duplicates first. Spaces and capitals hide duplicates, so normalise first.

  • Deleting every row with a gap. A row with a missing phone number may still have a good email address.

  • Filling gaps with 0. It changes sums and averages.

  • "Fixing" real values. A very large order can be real. Check before you change it.

  • Not writing anything down. Nobody, including you next month, can check a cleaning step that was never recorded.

Quiz

Check yourself

6 questions
  1. 1.Why should you trim spaces before removing duplicates?

  2. 2.An "amount" cell is empty. What is the safest choice?

  3. 3.What does the date 03/04/2026 mean?

  4. 4.You want one row per person in a contact list. Which key column is usually best?

  5. 5.A spreadsheet will not add up a price column. What is the most likely cause?

  6. 6.Why write down every cleaning step?

Practise it

Try it with the contact list worksheet and the free CSV Deduplicator. The Duplicate or not? exercise practises the key decision on its own.

Reuse this material

CC BY 4.0

You may copy, adapt and share it, also commercially, as long as you credit ManyPI and link back.

"Data cleaning basics" by ManyPI (https://manypi.com/edu/data-cleaning-basics), licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)