Thinking Like an Analyst · Lesson 2 of 6
Data Cleaning for Beginners: Fix Missing Values, Duplicates and Messy Formats
Analysts say cleaning takes half their time — and they are not exaggerating. Learn the common problems in real data, how to fix each one in Excel and pandas, and a checklist you can use on every dataset.
Here is a real-looking export from a college placement cell:
| Name | Branch | CGPA | Package | City |
|---|---|---|---|---|
| Priya Nair | CSE | 8.7 | 6.5 LPA | Bangalore |
| Rahul Verma | cse | 78% | 650000 | Bengaluru |
| Priya Nair | CSE | 8.7 | 6.5 LPA | Bangalore |
| Aman Gupta | Mech | 4,20,000 | bengaluru |
Try asking "What is the average package of CSE students placed in Bengaluru?" and every row fights you: a duplicate student, branch written two ways, CGPA as a percentage, packages in three formats, the same city spelt three ways with an extra space. This is normal. Clean data is something you produce, not something you receive.
The six problems you will see everywhere
- Duplicates — the same record entered twice, often from merged files.
- Missing values — blank cells, "NA", "-", or 0 used to mean "unknown".
- Inconsistent categories — CSE / cse / Computer Science; Bangalore / Bengaluru.
- Wrong data types — numbers stored as text ("4,20,000"), dates as text in mixed formats.
- Different units or scales — LPA vs rupees, CGPA vs percentage.
- Outliers and impossible values — a CGPA of 87, an age of 210, a delivery time of −5 minutes.
Fixing them, one by one
Duplicates
Decide what makes a row unique (a roll number, an order ID) before deleting anything. Two different students can share a name; one student should not share a roll number.
Missing values
There is no single right answer — it depends on why the value is missing:
- Leave it and report it — often the most honest choice. "CGPA missing for 12 of 340 students."
- Remove the row — fine if only a few rows are affected and they are not special in some way.
- Fill it — with the median (safer than the mean when there are outliers), a group median (median CGPA of that branch), or a clear label like "Unknown" for categories.
Never fill missing values with 0 unless 0 really is the value. An average package that counts "unknown" as ₹0 is simply wrong.
Inconsistent text
Trim spaces, standardise case, then map variations to one value with a small lookup table (Bangalore, bengaluru → Bengaluru).
Types and units
Convert everything to one unit in a new column — for example package_lpa — and keep the original column until you have checked the result.
The same cleaning in pandas
import pandas as pd
df = pd.read_csv("placements.csv")
df = df.drop_duplicates(subset=["roll_no"]) # one row per student
df["branch"] = df["branch"].str.strip().str.upper().replace({"COMPUTER SCIENCE": "CSE"})
df["city"] = df["city"].str.strip().str.title().replace({"Bangalore": "Bengaluru"})
# "6.5 LPA", "650000", "4,20,000" -> lakhs per annum
def to_lpa(value):
text = str(value).upper().replace(",", "").replace("LPA", "").strip()
number = float(text)
return number if number < 100 else number / 100000
df["package_lpa"] = df["package"].apply(to_lpa)
print(df.isna().sum()) # missing values per column
print(df.groupby("branch")["package_lpa"].median())
In Excel you would do the same with Remove Duplicates, TRIM, PROPER, Find & Replace and a helper column — or with Power Query, which records your cleaning steps so you can repeat them next month with one click.
A cleaning checklist for every dataset
- How many rows and columns? Does that match what you expected?
- What does one row represent? (One order? One customer? One day?)
- Any duplicates on the unique key?
- Missing values per column — and why are they missing?
- Correct data types? Dates as dates, numbers as numbers?
- Category spellings standardised?
- Minimum and maximum of every number — anything impossible?
- Write down every change you made, so someone else can repeat it.
Professional habit: never edit the raw file. Keep the original, clean in a copy (or in code), and document each step. When a manager asks "why does your number differ from finance's?", your notes are the answer.
Try it yourself: Download any public CSV (for example from data.gov.in), run through the eight-point checklist and write a short "data quality note": what you found, what you fixed and what you left alone and why.
Common interview questions
Try answering each one aloud before you open it.
1How do you handle missing values?
First understand why they are missing. Depending on that and how many there are, I report them, drop the affected rows, or impute them — for example with the median or a group median for numbers and an "Unknown" category for text — and I document the choice.
2Why use the median instead of the mean to fill missing numbers?
The median is not pulled by outliers. If a few packages are extremely high, the mean overstates the typical value, while the median stays representative.
3How do you decide whether a row is a duplicate?
Define the unique key for the dataset, such as an order ID or roll number, and check duplicates on that key rather than on names or other fields that can legitimately repeat.
Practise this
Build something with it
FAQs
Should I clean data in Excel or Python?
Small, one-off files are fine in Excel or Power Query. If you will repeat the cleaning or the data is large, use Python or SQL so the steps are saved and repeatable.
What is an outlier, and should I delete it?
An outlier is a value far from the rest. Check it first: if it is an error (CGPA 87), fix or remove it; if it is real (one very high package), keep it and consider using medians.
References & further reading
Finished this lesson?
Mark it complete. Create a free account to save it on every device.