Skip to main content
`Ctrl`+`K`

# pandas.errors.InvalidIndexError

exception pandas.errors.InvalidIndexError

  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

      >>> idx = pd.MultiIndex.from_product([["x", "y"], [0, 1]])
      >>> df = pd.DataFrame([[1, 1, 2, 2], [3, 3, 4, 4]], columns=idx)
      >>> df
          x       y
          0   1   0   1
      0   1   1   2   2
      1   3   3   4   4
      >>> df[:, 0]
      Traceback (most recent call last):
      InvalidIndexError: (slice(None, None, None), 0)