Q:

How to check whether a Pandas DataFrame is empty?

belongs to collection: Python Pandas Programs

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python Pandas Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to group DataFrame rows into list in pandas gr... >>
<< Python Pandas: Get index of rows which column matc...