Data Cleaning in Python: A Step-by-Step Guide for Beginners (2026)
Data cleaning is one of the most important skills in data science.
Data Cleaning in Python: A Step-by-Step Guide for Beginners (2026)

Data cleaning is one of the most important skills in data science.
In fact, data scientists spend 70–80% of their time cleaning data before building machine learning models.
You can have the best algorithms in the world, but if your data is messy, your model will fail.
In this complete guide, you will learn how to clean any dataset using Python and Pandas step by step.
Why Data Cleaning is Important
Real-world data is never perfect.
Common problems in datasets:
- Missing values
- Duplicate records
- Wrong data types
- Outliers
- Inconsistent formatting
- Noise and irrelevant data
If you skip data cleaning:
- Models become inaccurate
- Insights become misleading
- Business decisions become wrong
👉 Clean data = Better predictions
What You Will Learn
By the end of this tutorial, you will know how to:
- Import and explore datasets
- Handle missing values
- Remove duplicates
- Fix incorrect data types
- Handle outliers
- Standardize text data
- Prepare data for machine learning
We will use Python + Pandas.
Step 1: Import Libraries
Install required libraries:
pip install pandas numpy matplotlib seaborn
Import libraries:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
Step 2: Load the Dataset
df = pd.read_csv(“data.csv”)
df.head()
df.shape
df.columns
This helps you understand dataset structure quickly.
Step 3: Understand the Dataset
df.info()
df.describe()
This shows:
- Column names
- Data types
- Missing values
- Statistical summary
This stage is called data exploration.
Step 4: Handling Missing Values
Check missing values:
df.isnull().sum()
Option 1: Drop Missing Values
df.dropna(inplace=True)
Option 2: Fill Missing Values
df[“Age”].fillna(df[“Age”].mean(), inplace=True)
df[“Salary”].fillna(df[“Salary”].median(), inplace=True)
df[“City”].fillna(df[“City”].mode()[0], inplace=True)
Tip
- Mean → Normal distribution
- Median → Skewed distribution
Step 5: Remove Duplicate Rows
df.duplicated().sum()
df.drop_duplicates(inplace=True)
Duplicates reduce model accuracy.
Step 6: Fix Data Types
df.dtypes
df[“Date”] = pd.to_datetime(df[“Date”])
df[“Price”] = pd.to_numeric(df[“Price”])
Correct data types are essential for analysis.
Step 7: Handle Outliers
Visualize outliers:
sns.boxplot(x=df[“Salary”])
plt.show()
Remove using IQR method:
Q1 = df[“Salary”].quantile(0.25)
Q3 = df[“Salary”].quantile(0.75)
IQR = Q3 — Q1
df = df[(df[“Salary”] >= Q1–1.5*IQR) &
(df[“Salary”] <= Q3 + 1.5*IQR)]
Step 8: Standardize Text Data
Fix inconsistent text:
df[“Gender”] = df[“Gender”].str.lower()
df[“City”] = df[“City”].str.title()
df[“Name”] = df[“Name”].str.strip()
Step 9: Rename Columns
df.columns = df.columns.str.lower()
df.columns = df.columns.str.replace(“ “, “_”)
Clean column names improve readability.
Step 10: Feature Engineering
Create new features:
df[“salary_in_lakhs”] = df[“Salary”] / 100000
df[“year”] = df[“Date”].dt.year
Feature engineering improves model performance.
Step 11: Encode Categorical Data
df = pd.get_dummies(df, drop_first=True)
Machine learning models require numeric input.
Step 12: Save Cleaned Data
df.to_csv(“cleaned_data.csv”, index=False)
Your dataset is now ready for ML 🚀
Real-World Data Cleaning Workflow
Professional pipeline:
- Load data
- Understand data
- Handle missing values
- Remove duplicates
- Fix data types
- Handle outliers
- Feature engineering
- Encoding
- Save cleaned data
Common Beginner Mistakes
Avoid these mistakes:
❌ Jumping directly to ML ❌ Ignoring missing values ❌ Not checking duplicates ❌ Not visualizing data ❌ Skipping feature engineering
👉 Good data > Complex models
Tools Used for Data Cleaning
- Python (Pandas)
- SQL
- Excel
- Power BI
- OpenRefine
Pandas is the best tool for beginners.
Final Thoughts
Data cleaning is the backbone of every successful data science project. Without clean and reliable data, even the best models cannot produce meaningful results. By mastering data cleaning early, you gain a strong advantage over most beginners and build a solid foundation for analysis, modeling, and decision-making in real-world data science work.
Key Takeaways
- Clean data carefully
- Explore before modeling
- Follow a systematic workflow
메타데이터
- post_id
- 58dc68e09c83
- slug
- data-cleaning-in-python-a-step-by-step-guide-for-beginners-2026-58dc68e09c83
- url
- https://medium.com/@AmitSinha_7/data-cleaning-in-python-a-step-by-step-guide-for-beginners-2026-58dc68e09c83
- canonical_url
- https://medium.com/@AmitSinha_7/data-cleaning-in-python-a-step-by-step-guide-for-beginners-2026-58dc68e09c83
- author_url
- https://medium.com/@AmitSinha_7
- status
- ok
- fetched_at
- 2026-06-09 15:37:30