Home »
Python »
Python Programs
How to check whether a Pandas DataFrame is empty?
Given a DataFrame, we have to check whether a Pandas DataFrame is empty.
Submitted by Pranit Sharma, on April 29, 2022
Pandas is a special tool that allows us to perform complex manipulations of data effectively and efficiently. Inside pandas, we mostly deal with a dataset in the form of DataFrame. DataFrames are 2-dimensional data structures in pandas. DataFrames consists of rows, columns, and the data. A certain operation can be performed on DataFrames.
In pandas, we can check if a DataFrame is empty or not by using the following syntax:
Syntax:
DataFrame.empty()
By using the above syntax, we will get a Boolean value i.e., True if the DataFrame is empty and False if a DataFrame is not empty.
To work with Python Pandas, we need to import the pandas library. Below is the syntax,
import pandas as pd
Let us understand with the help of an example.
# Importing pandas package
import pandas as pd
# Creating an Empty dictionary
d = {}
# Creating an Empty DataFrame first
df=pd.DataFrame(d)
# Check if DataFrame is empty or
# not DataFrame
result = df.empty
# Display result
print(result)
Output:
True
Python Pandas Programs »