What is the notna function in Pandas?

The notna function detects non-missing values in a series or a data frame. Non-missing values are values that are not null.

Null values are denoted by None or NAN in Pandas.

Non-null values get mapped to True, whereas null values get mapped to False.

The illustration below shows how the notna function works in Pandas:

How does notna function work

Return value

The notna function returns a mask of boolean values, which indicates whether each value is null or non-null.

  • Null values are denoted by False.

  • Non-null values are denoted by True.

Example

The code snippet below shows how we can use the notna function in Pandas:

import pandas as pd
import numpy as np
# notna function on Series
ser = pd.Series([5, 6, np.NaN])
print("Original series")
print(ser)
print('\n')
print("Non-null Values")
print(ser.notna())
print('\n')
# notna function on Dataframe
df = pd.DataFrame(dict(age=[5, 6, np.NaN],
born=[pd.NaT, pd.Timestamp('1939-05-27'),
pd.Timestamp('1940-04-25')],
name=['Alfred', 'Batman', ''],
toy=[None, 'Batmobile', 'Joker']))
print("Original dataframe")
print(df)
print('\n')
print("Non-null Values")
print(df.notna())
print('\n')

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved