Skip to main content
`Ctrl`+`K`

# pandas.Index.droplevel

final Index.droplevel(level=0)

  Return index with requested level(s) removed.

  If resulting index has only 1 level left, the result will be of Index type, not MultiIndex. The original index is not modified inplace.

  Parameters:
    level int, str, or list-like, default 0

      If a string is given, must be the name of a level If list-like, elements must be names or indexes of levels.

  Returns:
    Index or MultiIndex

      Returns an Index or MultiIndex object, depending on the resulting index after removing the requested level(s).

  See also

  `Index.dropna`

    Return Index without NA/NaN values.

  Examples

      >>> mi = pd.MultiIndex.from_arrays(
      ...     [[1, 2], [3, 4], [5, 6]], names=["x", "y", "z"]
      ... )
      >>> mi
      MultiIndex([(1, 3, 5),
                  (2, 4, 6)],
                 names=['x', 'y', 'z'])

      >>> mi.droplevel()
      MultiIndex([(3, 5),
                  (4, 6)],
                 names=['y', 'z'])

      >>> mi.droplevel(2)
      MultiIndex([(1, 3),
                  (2, 4)],
                 names=['x', 'y'])

      >>> mi.droplevel("z")
      MultiIndex([(1, 3),
                  (2, 4)],
                 names=['x', 'y'])

      >>> mi.droplevel(["x", "y"])
      Index([5, 6], dtype='int64', name='z')