Pandas DataFrame Notnull Method

PythonPythonBeginner
Practice Now

Introduction

In this lab, we will learn how to use the notnull() method in Python's Pandas library. The notnull() method is used to detect existing values in a DataFrame.

VM Tips

After the VM startup is done, click the top left corner to switch to the Notebook tab to access Jupyter Notebook for practice.

Sometimes, you may need to wait a few seconds for Jupyter Notebook to finish loading. The validation of operations cannot be automated because of limitations in Jupyter Notebook.

If you face issues during learning, feel free to ask Labby. Provide feedback after the session, and we will promptly resolve the problem for you.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL python(("`Python`")) -.-> python/BasicConceptsGroup(["`Basic Concepts`"]) python(("`Python`")) -.-> python/DataStructuresGroup(["`Data Structures`"]) python(("`Python`")) -.-> python/ModulesandPackagesGroup(["`Modules and Packages`"]) python(("`Python`")) -.-> python/PythonStandardLibraryGroup(["`Python Standard Library`"]) python(("`Python`")) -.-> python/DataScienceandMachineLearningGroup(["`Data Science and Machine Learning`"]) python(("`Python`")) -.-> python/FunctionsGroup(["`Functions`"]) python/BasicConceptsGroup -.-> python/variables_data_types("`Variables and Data Types`") python/DataStructuresGroup -.-> python/lists("`Lists`") python/DataStructuresGroup -.-> python/tuples("`Tuples`") python/ModulesandPackagesGroup -.-> python/importing_modules("`Importing Modules`") python/PythonStandardLibraryGroup -.-> python/data_collections("`Data Collections`") python/DataScienceandMachineLearningGroup -.-> python/numerical_computing("`Numerical Computing`") python/DataScienceandMachineLearningGroup -.-> python/data_analysis("`Data Analysis`") python/FunctionsGroup -.-> python/build_in_functions("`Build-in Functions`") subgraph Lab Skills python/variables_data_types -.-> lab-68682{{"`Pandas DataFrame Notnull Method`"}} python/lists -.-> lab-68682{{"`Pandas DataFrame Notnull Method`"}} python/tuples -.-> lab-68682{{"`Pandas DataFrame Notnull Method`"}} python/importing_modules -.-> lab-68682{{"`Pandas DataFrame Notnull Method`"}} python/data_collections -.-> lab-68682{{"`Pandas DataFrame Notnull Method`"}} python/numerical_computing -.-> lab-68682{{"`Pandas DataFrame Notnull Method`"}} python/data_analysis -.-> lab-68682{{"`Pandas DataFrame Notnull Method`"}} python/build_in_functions -.-> lab-68682{{"`Pandas DataFrame Notnull Method`"}} end

Import the necessary libraries

import pandas as pd
import numpy as np

Create a DataFrame

df = pd.DataFrame([(0.0, np.nan, -1.0, 1.0),
                   (np.nan, 2.0, np.nan, np.nan),
                   (2.0, 3.0, np.nan, 9.0)],
                  columns=list('abcd'))

Print the original DataFrame

print("------The DataFrame is----------")
print(df)

Use the notnull() method to detect existing values

print("---------------------------------")
print(df.notnull())

Summary

In this lab, we learned how to use the notnull() method in Pandas to detect existing values in a DataFrame. The notnull() method returns a DataFrame consisting of boolean values for each element, where True indicates that the element is not a null value. We can use this method to check for missing or null values in our data.

Other Python Tutorials you may like