Pandas DataFrame.isnull() and notnull() Function

Minahil Noor Jan 30, 2023
  1. Syntax of pandas.DataFrame.isnull() and pandas.DataFrame.notnull():
  2. Example Codes: DataFrame.isnull() Method to Check for Null Values
  3. Example Codes: DataFrame.notnull() Method to Check for Not Null Values
Pandas DataFrame.isnull() and notnull() Function

Python Pandas DataFrame.isnull() function detects the missing value of an object and the DataFrame.notnull() function detects the non-missing value of an object.

Syntax of pandas.DataFrame.isnull() and pandas.DataFrame.notnull():

DataFrame.isnull()
DataFrame.notnull()

Return

Both the functions return scalar boolean for scalar input. For array input, both return an array of boolean indicating whether each corresponding element is valid.

Example Codes: DataFrame.isnull() Method to Check for Null Values

import pandas as pd
import numpy as np

dataframe=pd.DataFrame({'Attendance': {0: 60, 1: np.nan, 2: 80,3: 78,4: 95},
                        'Name': {0: 'Olivia', 1: 'John', 2: 'Laura',3: 'Ben',4: 'Kevin'},
                        'Obtained Marks': {0: np.nan, 1: 75, 2: 82, 3: np.nan, 4: 45}})
print("The Original Data frame is: \n")
print(dataframe)

dataframe1 = dataframe.isnull()
print("The output is: \n")
print(dataframe1)

Output:

The Original Data frame is: 

   Attendance    Name  Obtained Marks
0        60.0  Olivia             NaN
1         NaN    John            75.0
2        80.0   Laura            82.0
3        78.0     Ben             NaN
4        95.0   Kevin            45.0
The output is: 

   Attendance   Name  Obtained Marks
0       False  False            True
1        True  False           False
2       False  False           False
3       False  False            True
4       False  False           False

For null values, the function has returned True.

Example Codes: DataFrame.notnull() Method to Check for Not Null Values

import pandas as pd
import numpy as np

dataframe=pd.DataFrame({'Attendance': {0: 60, 1: np.nan, 2: 80,3: 78,4: 95},
                        'Name': {0: 'Olivia', 1: 'John', 2: 'Laura',3: 'Ben',4: 'Kevin'},
                        'Obtained Marks': {0: np.nan, 1: 75, 2: 82, 3: np.nan, 4: 45}})
print("The Original Data frame is: \n")
print(dataframe)

dataframe1 = dataframe.notnull()
print("The output is: \n")
print(dataframe1)

Output:

The Original Data frame is: 

   Attendance    Name  Obtained Marks
0        60.0  Olivia             NaN
1         NaN    John            75.0
2        80.0   Laura            82.0
3        78.0     Ben             NaN
4        95.0   Kevin            45.0
The output is: 

   Attendance  Name  Obtained Marks
0        True  True           False
1       False  True            True
2        True  True            True
3        True  True           False
4        True  True            True

The function has returned True for not null values.

Related Article - Pandas DataFrame