pythonpandasdataframemembershipany

How do I check if a pandas DataFrame is empty?


How do I check if a pandas DataFrame is empty? I'd like to print some message in the terminal if the DataFrame is empty.


Solution

  • 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