This tutorial shows you how to check if Pandas DataFrame is empty.
You can use df.empty
method to check if DataFrame is empty. below is an example:
Example 1: Check if Pandas DataFrame is Empty
if df.empty: print('DataFrame is empty!')
Example 2: Check Using The len() Function
In the below example, it checks if the Pandas DataFrame is empty using the len(df.index)
function:
import pandas as pd import numpy as np df = pd.DataFrame(np.random.randn(10000, 4), columns=list('ABCD')) def empty(df): return df.empty def lenz(df): return len(df) == 0 def lenzi(df): return len(df.index) == 0