Pandas How To Uncategorized How to check if Pandas dataframe is empty

How to check if Pandas dataframe is empty

Here’s how to check if Pandas dataframe is empty.

Is the dataframe empty?

It is easy to check in Pandas if the dataframe is empty. Pandas offers a dedicated function to check if a dataframe is empty. The functions name is just empty.

Use below code as follows:

import pandas as pd

df = pd.DataFrame()

print(f"Is the dataframe empty? " + str(df.empty))

print(df)

The code returns boolean value TRUE or FALSE.

Output:

Is the dataframe empty? True
Empty DataFrame
Columns: []
Index: []

Alternatively, you can write a simple if else condition.

if df.empty:
    print("DataFrame is empty")
else:
    print("DataFrame is not empty")
Tags:

1 thought on “How to check if Pandas dataframe is empty”

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post