Skip to main content

Pandas notnull()

In this tutorial, you will learn about the notnull() method in Pandas with the help of examples.

The notnull() method in Pandas is used to detect existing (non-missing) values in the data.

Example

import pandas as pd

# sample DataFrame with missing values
data = {'A': [1, None, 3],
        'B': [4, 5, None]}

df = pd.DataFrame(data)

# detect non-missing values
not_null_values = df.notnull()

print(not_null_values)
 
'''
Output

       A      B
0   True   True
1  False   True
2   True  False
'''

notnull() Syntax

The syntax of the notnull() method in Pandas is:

df.notnull()

notnull() Arguments

The notnull() method does not take any arguments.


notnull() Return Value

The notnull() method returns a Boolean same-sized object indicating if the values are non-NA. True stands for non-missing values and False stands for missing values.


Example: Filtering Data using notnull()

import pandas as pd

# sample DataFrame with missing values
data = {'A': [1, None, 3],
        'B': [4, 5, None]}

df = pd.DataFrame(data)

# detect non-missing values
filtered_df = df[df['A'].notnull()]

print(filtered_df)

Output

     A    B
0  1.0  4.0
2  3.0  NaN

In this example, we used notnull() in combination with indexing to filter rows based on non-missing values in column A.