HOWTO · Pandas
How to Check if a Cell Is Empty in Pandas
This tutorial details how to check if a cell in a Pandas DataFrame is empty.
On this page
Pandas checks identify values that the library recognizes as missing. They do not treat every value that looks blank as missing: NaN, None, and NaT are examples of missing-value representations, while an empty string ("") is an ordinary string unless you explicitly convert it. This distinction matters when imported data uses blank text to represent absent information.
Understand What Counts as Missing in Pandas
Use isna() or its alias isnull() to create a Boolean mask: True marks a recognized missing value and False marks a present value. The same operation works on a scalar, a Series (one column), or a DataFrame. The mask preserves the shape and labels of the object it checks.
The examples below use None to create missing entries. The supplied execution evidence includes outputs for all four runnable Python examples.
Check One Cell or a Column with isna() or isnull()
Run this example:
import pandas as pd
df = pd.DataFrame({"name": ["Ari", "Bo", "Cy"], "score": [8, None, 6]}, index=[10, 11, 12])
cell_missing = pd.isna(df.loc[11, "score"])
column_mask = df["score"].isna()
print(cell_missing)
print(column_mask.tolist())
loc selects by row and column labels, so df.loc[11, "score"] checks the cell at row label 11. To select by position, use iloc, for example df.iloc[1, 1]. The row label and row position can differ when a DataFrame has a custom index. isna() and isnull() are equivalent aliases; choose either name consistently. The Pandas isnull() documentation describes the same missing-value check.
For a whole column, df["score"].isna() returns one Boolean per row. For a whole DataFrame, df.isna() returns a Boolean DataFrame with the same row and column labels. Use these masks to inspect results or select matching rows, such as df.loc[df["score"].isna()].
Check Whether Any Missing Values Exist with any()
Call any() on a column mask to get one Boolean answer for that column. For a DataFrame, df.isna().any() returns a Boolean Series with one result per column. Reduce that Series with another any() to ask whether any column contains a missing value:
import pandas as pd
df = pd.DataFrame({"name": ["Ari", "Bo", "Cy"], "score": [8, None, 6]})
missing_by_column = df.isna().any()
missing_anywhere = missing_by_column.any()
print(missing_by_column.to_dict())
print(missing_anywhere)
Python’s any() function returns true when at least one item is true. Calling it once on a DataFrame mask answers per column; calling it again on that result produces a single answer for the DataFrame.
Count Missing Values with sum()
Because Boolean True values count as 1 and False values as 0 when summed, summing a missing-value mask gives a count. Sum a Series mask for one column, or sum a DataFrame mask for per-column counts. Add a second sum to get one total across all cells:
import pandas as pd
df = pd.DataFrame({"name": ["Ari", "Bo", "Cy"], "score": [8, None, 6]})
counts_by_column = df.isna().sum()
total_missing = counts_by_column.sum()
print(counts_by_column.to_dict())
print(total_missing)
This counts only values Pandas recognizes as missing. If blank strings in an imported column should count too, normalize them first (for example, replace "" with None) and then build the mask.
Find Row Labels for Missing Values
Use the Boolean mask to select the Series index wherever a value is missing. The returned values are row labels, not row positions:
import pandas as pd
df = pd.DataFrame({"score": [8, None, 6, None]}, index=[10, 11, 12, 13])
missing_row_labels = df.index[df["score"].isna()].tolist()
print(missing_row_labels)
For general Pandas data, this mask-based approach handles the missing-value representations recognized by Pandas. numpy.isnan is narrower: it tests NaN values in compatible numeric data and may not accept values such as None or NaT. Prefer isna() when the column’s values may use different missing-value representations. Use numpy.isnan only when the data type and values are suitable for that function.