
To check if a Pandas DataFrame is empty, we use the DataFrame.empty property. If a DataFrame is empty then True is returned and if a DataFrame is not empty then False is returned.
Empty DataFrame –
Let’s create an Empty DataFrame.
import pandas as pd
# create an empty dataframe
df = pd.DataFrame()
# check if empty or not
df.empty
#output
True
Since the DataFrame is empty, the DataFrame.empty property returns True.
Non-Empty DataFrame –
Let’s create a DataFrame that is not empty.
# create a non-empty dataframe
df = pd.DataFrame({'Name':['Mike','Eleven','Dustin','Max','Lucas'],
'Marks':[80, 95, 70, 85, 80]})
# check if it is empty or not
df.empty
#output
False
Since the DataFrame is not empty, we get False as a answer.