Check if a Pandas DataFrame is Empty

You can use the attribute df.empty to check whether it's empty or not. True if DataFrame is entirely empty (no items), meaning any of the axes are of length 0.
import pandas as pd import numpy as np df = pd.DataFrame({'Name' : []}) if df.empty: print('DataFrame is empty!') else: print('Not empty!')
DataFrame is empty!
If you have only NaNs in your DataFrame, it is not considered as empty.
import pandas as pd import numpy as np df = pd.DataFrame({'Name' : [np.nan]}) if df.empty: print('DataFrame is empty!') else: print('Not empty!')
Not empty!

Using len()

You can use the len function for checking DataFrame is empty or not. It's much faster than df.empty.
import pandas as pd import numpy as np df = pd.DataFrame() df['Name'] = ['John', 'Doe', 'Bill'] df['Promoted'] = [True, False,True] df['Marks'] = [82, 38, 63] df.drop(df.index, inplace=True) if len(df.index) == 0: print('DataFrame is empty!') else: print('Not empty!')
DataFrame is empty!