How to check whether a pandas DataFrame is empty?

前端 未结 5 817
别跟我提以往
别跟我提以往 2020-12-02 04:01

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.

5条回答
  •  旧巷少年郎
    2020-12-02 04:37

    I prefer going the long route. These are the checks I follow to avoid using a try-except clause -

    1. check if variable is not None
    2. then check if its a dataframe and
    3. make sure its not empty

    Here, DATA is the suspect variable -

    DATA is not None and isinstance(DATA, pd.DataFrame) and not DATA.empty
    

提交回复
热议问题