Pandas DataFrame Empty – Python

The empty property – Indicator whether DataFrame is empty.

True if DataFrame is entirely empty (no items), meaning any of the axes are of length 0.

  • Syntax:
  • Returns:
    bool = If DataFrame is empty, return True, if not return False.
  • Notes:
    If DataFrame contains only NaNs, it is still not considered empty. See the example below.
  • Example 1:
    '''An example of an actual empty DataFrame. Notice the index is empty:'''
    >>> df_empty = pd.DataFrame({'A' : []})
    >>> df_empty
    Empty DataFrame
    Columns: [A]
    Index: []
    >>> df_empty.empty
  • Example 2:
    '''If we only have NaNs in our DataFrame, it is not considered empty! We
    will need to drop the NaNs to make the DataFrame empty:'''
    >>> df = pd.DataFrame({'A' : [np.nan]})
    >>> df
    0 NaN
    >>> df.empty
    >>> df.dropna().empty
  • Series.dropna : Return series without null values.
  • DataFrame.dropna : Return DataFrame with labels on given axis omitted where (all or any) data are missing.