0
0
Pandasdata~5 mins

Counting missing values in Pandas

Choose your learning style9 modes available
Introduction

We count missing values to understand where data is incomplete. This helps us decide how to clean or fix the data.

Checking if survey responses have unanswered questions.
Finding missing sales data in a store's records.
Identifying gaps in sensor readings over time.
Verifying if any customer information is missing before analysis.
Syntax
Pandas
df.isna().sum()

df.isna() creates a table showing True where data is missing.

.sum() adds up True values (missing data) for each column.

Examples
Count missing values in each column of the DataFrame df.
Pandas
df.isna().sum()
Count missing values only in the Age column.
Pandas
df['Age'].isna().sum()
Count total missing values in the entire DataFrame.
Pandas
df.isna().sum().sum()
Sample Program

This code creates a small table with some missing data. It counts missing values per column and total missing values in the whole table.

Pandas
import pandas as pd

data = {'Name': ['Alice', 'Bob', None, 'David'],
        'Age': [25, None, 30, 22],
        'City': ['NY', 'LA', 'LA', None]}

df = pd.DataFrame(data)

missing_per_column = df.isna().sum()
total_missing = df.isna().sum().sum()

print('Missing values per column:')
print(missing_per_column)
print('\nTotal missing values in DataFrame:')
print(total_missing)
OutputSuccess
Important Notes

Missing values are shown as NaN in pandas.

You can also use df.isnull() which works the same as df.isna().

Summary

Use df.isna().sum() to count missing values per column.

Use df.isna().sum().sum() to count all missing values in the DataFrame.

Counting missing data helps you understand data quality before analysis.