Friday, October 3, 2025
HomeLanguagesPandas isnull() and notnull() Method

Pandas isnull() and notnull() Method

Pandas is one of those packages and makes importing and analyzing data much easier. While making a Data Frame from a Pandas CSV file, many blank columns are imported as null values into the DataFrame which later creates problems while operating that data frame. Pandas isnull() and notnull() methods are used to check and manage NULL values in a data frame.

Pandas DataFrame isnull() Method

Syntax: Pandas.isnull(“DataFrame Name”) or DataFrame.isnull()

Parameters: Object to check null values for

Return Type: Dataframe of Boolean values which are True for NaN values 

To download the CSV file used, Click Here.

Example

In the following example, The Team column is checked for NULL values and a boolean series is returned by the isnull() method which stores True for ever NaN value and False for a Not null value.

Python3




# importing pandas package
import pandas as pd
 
# making data frame from csv file
data = pd.read_csv("employees.csv")
 
# creating bool series True for NaN values
bool_series = pd.isnull(data["Team"])
 
# filtering data
# displaying data only with team = NaN
data[bool_series]


Output: 

As shown in the output image, only the rows having Team=NULL are displayed. 

Pandas DataFrame isnull() Method

 

Pandas DataFrame notnull() Method

Syntax: Pandas.notnull(“DataFrame Name”) or DataFrame.notnull()

Parameters: Object to check null values for

Return Type: Dataframe of Boolean values which are False for NaN values

Example 

In the following example, the Gender column is checked for NULL values and a boolean series is returned by the notnull() method which stores True for every NON-NULL value and False for a null value.

Python3




# importing pandas package
import pandas as pd
 
# making data frame from csv file
data = pd.read_csv("employees.csv")
 
# creating bool series False for NaN values
bool_series = pd.notnull(data["Gender"])
 
# displayed data only with team = NaN
data[bool_series]


Output: 

As shown in the output image, only the rows having some value in Gender are displayed. 

Pandas DataFrame notnull() Method

 

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32332 POSTS0 COMMENTS
Milvus
85 POSTS0 COMMENTS
Nango Kala
6703 POSTS0 COMMENTS
Nicole Veronica
11868 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11929 POSTS0 COMMENTS
Shaida Kate Naidoo
6819 POSTS0 COMMENTS
Ted Musemwa
7080 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6776 POSTS0 COMMENTS