Contents
Data Cleaning Techniques
Data cleaning fixes errors and inconsistencies in a dataset, so the information going into your model is accurate and usable.
Common data cleaning tasks
- Removing duplicate rows.
- Fixing incorrect data types.
- Correcting inconsistent text formatting, such as mismatched capitalization.
- Removing irrelevant columns that do not help the model.
Fixing data types
Sometimes numbers get stored as text, which breaks calculations later.
import pandas as pd
df = pd.read_csv("data.csv")
df["Price"] = df["Price"].astype(float)astype(float) converts the Price column from text to numbers, so you can use it in mathematical operations and feed it into a model.
Fixing inconsistent text
Text data often has mismatched casing, which can be treated as different categories by mistake.
df["City"] = df["City"].str.lower().str.strip()str.lower() makes all text lowercase, and str.strip() removes extra spaces, so values like "Delhi" and " delhi " are treated as the same category.
Dropping unnecessary columns
df = df.drop(columns=["Unnamed: 0"])This removes a column that adds no value to the analysis, like leftover index columns from a CSV file.
Clean data ensures a model learns from accurate patterns, not errors hidden in the dataset.
Machine Learning Tutorial
Abhishek Pati








