Detecting Missing Values in Pandas – Best Techniques 2026
Before you can handle missing values, you must first detect and understand them properly. In 2026, Pandas offers several powerful and efficient methods to identify, quantify, and visualize missing data in your datasets.
TL;DR — Essential Detection Commands
df.isna().sum()– Count missing values per columndf.isna().mean() * 100– Percentage of missing valuesdf.isnull().any()– Which columns have missing valuesdf[df.isna().any(axis=1)]– Show rows with any missing values
1. Basic Missing Value Detection
import pandas as pd
df = pd.read_csv("sales_data.csv", parse_dates=["order_date"])
# Total missing values per column
missing_count = df.isna().sum()
print("Missing values per column:")
print(missing_count)
# Percentage of missing values
missing_pct = df.isna().mean() * 100
print("
Percentage missing:")
print(missing_pct.round(2))
2. Advanced Detection Techniques
# Columns that have at least one missing value
cols_with_missing = df.columns[df.isna().any()]
print("Columns with missing values:", cols_with_missing.tolist())
# Rows that contain missing values
rows_with_missing = df[df.isna().any(axis=1)]
print(f"
Number of rows with missing values: {len(rows_with_missing)}")
# Detailed view of missingness pattern
missing_pattern = df.isna().sum(axis=1).value_counts().sort_index()
print("
Number of missing values per row:")
print(missing_pattern)
3. Visualizing Missing Values (Very Useful)
import seaborn as sns
import matplotlib.pyplot as plt
plt.figure(figsize=(12, 8))
# Heatmap of missing values
sns.heatmap(df.isna(), cbar=False, cmap="viridis", yticklabels=False)
plt.title("Missing Values Heatmap")
plt.show()
# Bar plot of missing values percentage
missing_pct.sort_values(ascending=False).plot(
kind="bar",
figsize=(12, 6),
color="tomato"
)
plt.title("Percentage of Missing Values by Column")
plt.ylabel("Percentage (%)")
plt.xticks(rotation=45, ha="right")
plt.tight_layout()
plt.show()
4. Best Practices for Detecting Missing Values in 2026
- Always start with
df.isna().sum()anddf.isna().mean()*100 - Check both column-wise and row-wise missingness patterns
- Use visualization (heatmap or bar plot) to understand the pattern of missing data
- Investigate **why** the data is missing — this guides your handling strategy
- Document the percentage and pattern of missing values in your analysis notes
Conclusion
Properly detecting missing values is the first and most important step in data cleaning. In 2026, combining isna().sum(), percentage calculations, and visualizations gives you a complete picture of missingness in your dataset. Never jump straight to filling or dropping missing values without first understanding their pattern and potential causes.
Next steps:
- Run a full missing value analysis on one of your current datasets using the techniques shown above