Fix Python – How to check whether a pandas DataFrame is empty?

Question

Asked By – Nilani Algiriyage

How to check whether a pandas DataFrame is empty? In my case I want to print some message in terminal if the DataFrame is empty.

Now we will see solution for issue: How to check whether a pandas DataFrame is empty?


Answer

You can use the attribute df.empty to check whether it’s empty or not:

if df.empty:
    print('DataFrame is empty!')

Source: Pandas Documentation

This question is answered By – aIKid

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0