Reference Materials
Certification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
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.