Check if DataFrame is Empty

To check if DataFrame is empty in Pandas, use pandas.DataFrame.empty attribute. This attribute returns a boolean value of true if this DataFrame is empty, or false if this DataFrame is not empty.

In this tutorial, we will learn how to check if DataFrame is empty in Pandas using DataFrame.empty attribute.

Examples

Empty DataFrame

In the following program, we create an empty DataFrame and programmatically check if this DataFrame is empty or not.

Example.py

</>
Copy
import pandas as pd

df = pd.DataFrame()

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

Output

DataFrame is empty.

Non-empty DataFrame

In the following program, we create a DataFrame with some values in it and programmatically check if this DataFrame is empty or not.

Example.py

</>
Copy
import pandas as pd

df = pd.DataFrame(
    {'name': ["apple", "banana", "cherry"], 'quant': [40, 50, 60]})

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

Output

DataFrame is not empty.

Conclusion

In this Pandas Tutorial, we learned how to check if a DataFrame is empty or not using DataFrame.empty attribute.