Member-only story
Mastering Missing Data: Part 2 Basic Imputation Techniques
In Part 1, we explored missing data, its types, and how to detect it. Now, it’s time to fill those gaps! Feature imputation is the process of replacing missing values with plausible data. In this tutorial, we’ll cover mean, median, and mode imputation, which are the most widely used strategies for beginners.
Why Imputation Matters
Simply dropping rows or columns with missing values can lead to:
- Loss of valuable information
- Smaller training datasets
- Bias in statistical measures
Instead, imputation allows you to preserve your data while maintaining integrity.
1. Mean Imputation
Mean imputation replaces missing numeric values with the average of the available data.
import pandas as pd
import numpy as np
# Sample dataset
data = {
'Age': [25, np.nan, 30, 22, np.nan, 28, 32, 27],
'Salary': [50000, 60000, np.nan, 52000, 58000, 60000, np.nan, 62000]
}
df = pd.DataFrame(data)
# Mean imputation
df['Age'].fillna(df['Age'].mean(), inplace=True)
df['Salary'].fillna(df['Salary'].mean(), inplace=True)
df✅ Pros: Simple, fast, works well if data is normally distributed
⚠️ Cons: Reduces variance…







