Exception raised when attempting to use an invalid index key.
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)
© 2008–2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
© 2011–2025, Open source contributors
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/2.3.0/reference/api/pandas.errors.InvalidIndexError.html