Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Data preprocessing
  • Data Manipulation
  • Data Analysis using Pandas
  • EDA
  • Pandas Exercise
  • Pandas AI
  • Numpy
  • Matplotlib
  • Plotly
  • Data Analysis
  • Machine Learning
  • Data science
Open In App
Next Article:
Pandas DataFrame notnull() Method
Next article icon

Pandas isnull() and notnull() Method

Last Updated : 30 Nov, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will delve into the Pandas isnull() and notnull() methods, essential tools provided by the Pandas library for simplifying the import and analysis of data. Pandas prove to be a valuable package for data manipulation, particularly when creating DataFrames from Pandas CSV files. Often, during this process, blank columns are imported as null values, potentially causing complications in subsequent DataFrame operations.

The isnull() and notnull() methods in Pandas address this issue by facilitating the identification and management of NULL values within a data frame DataFrame. These methods offer a means to systematically check for the presence of null values, enabling users to take appropriate actions, such as filtering or replacing, to enhance the overall integrity and usability of the data frame.

Pandas DataFrame isnull() Method

Syntax: pd.isnull(dataframe) or dataframe.isnull()

Parameters: Object to check null values for (DataFrame)

Return Type: DataFrame of Boolean values where True indicates the presence of NaN (Not a Number) values in the specified DataFrame. 

To download the CSV file used, Click Here.

Example: pandas.isnull() Method

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("/content/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

file-llll

Output

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

Count NaN values in Pandas DataFrame

In the following example , the code reads a CSV file (“employees.csv”) into a Pandas DataFrame named “data.” It identifies NaN values in the “Team” column using a boolean series, counts the missing values, and prints the count. Additionally, it displays a subset of the data containing only rows where “Team” values are NaN.

Python3




import pandas as pd
 
# Making a DataFrame from a CSV file
data = pd.read_csv("employees.csv")
 
# Creating a boolean series marking True for NaN values in the "Team" column
bool_series = pd.isnull(data["Team"])
 
# Counting missing values in the "Team" column
missing_values_count = bool_series.sum()
 
# Displaying data only with "Team" values as NaN
filtered_data = data[bool_series]
 
print("Count of missing values in the 'Team' column:", missing_values_count)
 
 

Output

Count of missing values in the 'Team' column: 43

Pandas DataFrame notnull() Method

Syntax: pd.notnull(dataframe) or dataframe.notnull()

Parameters: Object to check null values for (DataFrame)

Return Type: DataFrame of Boolean values where False indicates the presence of NaN (Not a Number) values in the specified DataFrame.

Example: notnull() Method

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("/content/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

file-22

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

Filter a Pandas Dataframe Based on Null Values

In the following example , below code reads a CSV file (“employees.csv”) into a Pandas DataFrame named “data.” It creates a boolean series, bool_series, marking False for NaN values in the “Gender” column. The code then filters the DataFrame to display only the rows with non-null “Gender” values, creating a subset of data that excludes entries with missing gender information. Finally, it prints and shows this subset of data.

Python3




import pandas as pd
 
# Making a DataFrame from a CSV file
data = pd.read_csv("employees.csv")
 
# Creating a boolean series marking False for NaN values in the "Gender" column
bool_series = pd.notnull(data["Gender"])
 
# Displaying data only with non-null "Gender" values
filtered_data = data[bool_series]
 
print("Data with non-null 'Gender' values:")
print(filtered_data)
 
 

Output

kngttgjksdhkjgh

Output



Next Article
Pandas DataFrame notnull() Method

K

Kartikaybhutani
Improve
Article Tags :
  • Python
  • Pandas-DataFrame-Methods
  • Python pandas-dataFrame
  • python-modules
  • Python-pandas
Practice Tags :
  • python

Similar Reads

  • Pandas DataFrame notnull() Method
    Pandas dataframe.notnull() function detects existing/ non-missing values in the dataframe. The function returns a boolean object having the same size as that of the object on which it is applied, indicating whether each individual value is a na value or not. All of the non-missing values gets mapped
    2 min read
  • Python | Pandas Index.notnull()
    Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.notnull() function detect existing (non-missing) values. This function re
    2 min read
  • Python | Decimal is_nan() method
    Decimal#is_nan() : is_nan() is a Decimal class method which checks whether the Decimal value is NaN value. Syntax: Decimal.is_nan() Parameter: Decimal values Return: true - if the Decimal value is NaN value; otherwise false Code #1 : Example for is_nan() method # Python Program explaining # is_nan()
    2 min read
  • Python | Decimal is_snan() method
    Decimal#is_snan() : is_snan() is a Decimal class method which checks whether the Decimal value is a signaling NaN Syntax: Decimal.is_snan() Parameter: Decimal values Return: true - if the Decimal value is a signaling NaN; otherwise false Code #1 : Example for is_snan() method # Python Program explai
    2 min read
  • Python | Decimal is_qnan() method
    Decimal#is_qnan() : is_qnan() is a Decimal class method which checks whether the Decimal value is quite NaN value. Syntax: Decimal.is_qnan() Parameter: Decimal values Return: true - if the Decimal value is quite NaN value; otherwise false Code #1 : Example for is_qnan() method # Python Program expla
    2 min read
  • Python | numpy.isnat() method
    With the help of numpy.isnat() method, we can get the boolean value as true if date defined in a np.datetime64() method is not a time by using numpy.isnat() method. Syntax : numpy.isnat() Return : Return the boolean value if time is not found. Example #1 : In this example we can see that by using nu
    1 min read
  • Python | Pandas Index.isnull()
    Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.isnull() function detect missing values. It return a boolean same-sized o
    2 min read
  • Pandas DataFrame.dropna() Method
    Pandas is one of the packages that makes importing and analyzing data much easier. Sometimes CSV file has null values, which are later displayed as NaN in Pandas DataFrame. Pandas dropna() method allows the user to analyze and drop Rows/Columns with Null values in different ways. Pandas DataFrame.dr
    3 min read
  • Python | sympy.is_nonzero() method
    In sympy module, we can test whether a given number n is nonzero or not using sympy.is_nonzero() function. Syntax: sympy.is_nonzero(n) Parameter: n; number to be tested Return: bool value result Code #1: C/C++ Code # Python program to check nonzero # using sympy.is_nonzero() method # importing sympy
    1 min read
  • Pandas DataFrame interpolate() Method | Pandas Method
    Python is a great language for data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier.  Python Pandas interpolate() method is used to fill NaN values in the DataFrame or Series us
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences