pandas.Index.empty#

property Index.empty[source]#

Indicator whether Index is empty.

An Index is considered empty if it has no elements. This property can be useful for quickly checking the state of an Index, especially in data processing and analysis workflows where handling of empty datasets might be required.

Returns:
bool

If Index is empty, return True, if not return False.

See also

Index.size

Return the number of elements in the underlying data.

Examples

>>> idx = pd.Index([1, 2, 3])
>>> idx
Index([1, 2, 3], dtype='int64')
>>> idx.empty
False
>>> idx_empty = pd.Index([])
>>> idx_empty
Index([], dtype='object')
>>> idx_empty.empty
True

If we only have NaNs in our DataFrame, it is not considered empty!

>>> idx = pd.Index([np.nan, np.nan])
>>> idx
Index([nan, nan], dtype='float64')
>>> idx.empty
False