🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEpandas

pandas Documentation

LOADING ENGINE...

df.isna()

AI & DATA SCIENCE // df-isna

df.isna() returns a boolean DataFrame or Series the same shape as the original, marking True wherever a value is missing (NaN or None).

Syntax

df.isna()

Deep Dive Course

isna(), and its identical alias isnull(), checks every element for missingness, which in pandas covers both NaN, the standard floating-point missing marker, and None, Python's own null value, treating both as equally missing. It's the standard first step for understanding a dataset's missing-data situation: chaining .sum() onto it gives a per-column count of missing values, and .any() checks whether any missing values exist at all, in a specific column or across the whole DataFrame.

1Understanding df.isna()

isna(), and its identical alias isnull(), checks every element for missingness, which in pandas covers both NaN, the standard floating-point missing marker, and None, Python's own null value, treating both as equally missing. It's the standard first step for understanding a dataset's missing-data situation: chaining .sum() onto it gives a per-column count of missing values, and .any() checks whether any missing values exist at all, in a specific column or across the whole DataFrame.

💡

Chain .sum() onto isna() to get a quick per-column count of missing values across an entire DataFrame in one line, rather than checking each column individually.

editor.html
import pandas as pd
import numpy as np

df = pd.DataFrame({"a": [1, np.nan, 3], "b": [np.nan, 5, 6]})
print(df.isna())
localhost:3000

2Practical Example

Here is a real-world application of df.isna() showing how it is used in production Pandas code.

editor.html
import pandas as pd
import numpy as np

df = pd.DataFrame({"a": [1, np.nan, 3], "b": [np.nan, 5, 6]})
print(df.isna().sum())
localhost:3000

3Best Practices

Follow these guidelines when working with df.isna():

1. Use df.isna().sum() right after loading a dataset to get a per-column missing-value count as part of your initial data-quality check

2. Use isna() combined with boolean indexing to inspect the specific rows that have missing values in a column, before deciding how to handle them

3. Remember isna() and isnull() are exact aliases for the same method — pick whichever name you and your team prefer and use it consistently

⚠️

Tip: Chain .sum() onto isna() to get a quick per-column count of missing values across an entire DataFrame in one line, rather than checking each column individually.

editor.html
import pandas as pd
import numpy as np

df = pd.DataFrame({"a": [1, np.nan, 3], "b": [np.nan, 5, 6]})
print(df.isna())
localhost:3000

Examples

Example 01Basic Usage
import pandas as pd
import numpy as np

df = pd.DataFrame({"a": [1, np.nan, 3], "b": [np.nan, 5, 6]})
print(df.isna())
Example 02Advanced Example
import pandas as pd
import numpy as np

df = pd.DataFrame({"a": [1, np.nan, 3], "b": [np.nan, 5, 6]})
print(df.isna().sum())

Best Practices

  • Use df.isna().sum() right after loading a dataset to get a per-column missing-value count as part of your initial data-quality check
  • Use isna() combined with boolean indexing to inspect the specific rows that have missing values in a column, before deciding how to handle them
  • Remember isna() and isnull() are exact aliases for the same method — pick whichever name you and your team prefer and use it consistently

Interview Question

Why does df.isna().sum() give a per-column count of missing values, when isna() itself returns a DataFrame of booleans, not numbers?

Hint: Think about how True and False behave when you try to add them up.

isna() returns a DataFrame where each True marks a missing value and each False marks a present one, and booleans in pandas, like in NumPy, behave as 1 and 0 respectively in arithmetic contexts. Calling .sum() on that boolean DataFrame sums each column independently by default, effectively adding up how many True values, missing entries, each column contains, which produces exactly the per-column missing-value count as a Series, one number per column.

Exercises

MediumPractice using df.isna() in a real scenario.
View Solution
import pandas as pd
import numpy as np

df = pd.DataFrame({"a": [1, np.nan, 3], "b": [np.nan, 5, 6]})
print(df.isna())

Frequently Asked Questions

Why does df.isna().sum() give a per-column count of missing values, when isna() itself returns a DataFrame of booleans, not numbers?

isna() returns a DataFrame where each True marks a missing value and each False marks a present one, and booleans in pandas, like in NumPy, behave as 1 and 0 respectively in arithmetic contexts. Calling .sum() on that boolean DataFrame sums each column independently by default, effectively adding up how many True values, missing entries, each column contains, which produces exactly the per-column missing-value count as a Series, one number per column.

Related Functions

df-notnadf-dropnadf-fillna