pandas.errors.InvalidIndexError#

exception pandas.errors.InvalidIndexError[source]#

Exception raised when attempting to use an invalid index key.

This exception is triggered when a user attempts to access or manipulate data in a pandas DataFrame or Series using an index key that is not valid for the given object. This may occur in cases such as using a malformed slice, a mismatched key for a MultiIndex, or attempting to access an index element that does not exist.

See also

MultiIndex

A multi-level, or hierarchical, index object for pandas objects.

Examples

>>> df = pd.DataFrame({"a": [1, 2], "b": [3, 4]})
>>> df[("a", slice(None))]
Traceback (most recent call last):
InvalidIndexError: ('a', slice(None, None, None))