The empty
property of the DataFrame
class indicates whether a given dataframe is empty. It is a boolean property, meaning it returns True
if the dataframe is empty. NaNs
values are considered to be valid entries in the dataframe, and hence if the data frame contains only NaNs
, it is not considered empty.
Note: Refer to What is pandas in Python to learn more about pandas.
Dataframe.empty
import pandas as pdimport numpy as npdf = pd.DataFrame({"col1" : []})print(df)print("Is the above dataframe empty? %s" % (df.empty, ))print("-" * 5)df = pd.DataFrame({"col1" : [np.nan], "col2" : [np.nan]})print(df)print("Is the above dataframe empty? %s" % (df.empty, ))
pandas
and numpy
modules.df
.empty
attribute on df
.NaNs
to the df
dataframe.empty
attribute on df
.