pyspark.pandas.Index.droplevel

Index.droplevel(level: Union[int, Any, Tuple[Any, …], List[Union[int, Any, Tuple[Any, …]]]]) → pyspark.pandas.indexes.base.Index

Return index with requested level(s) removed. If resulting index has only 1 level left, the result will be of Index type, not MultiIndex.

Parameters
levelint, str, tuple, 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

Examples

>>> midx = ps.DataFrame({'a': ['a', 'b']}, index=[['a', 'x'], ['b', 'y'], [1, 2]]).index
>>> midx  
MultiIndex([('a', 'b', 1),
            ('x', 'y', 2)],
           )
>>> midx.droplevel([0, 1])  
Int64Index([1, 2], dtype='int64')
>>> midx.droplevel(0)  
MultiIndex([('b', 1),
            ('y', 2)],
           )
>>> midx.names = [("a", "b"), "b", "c"]
>>> midx.droplevel([('a', 'b')])  
MultiIndex([('b', 1),
            ('y', 2)],
           names=['b', 'c'])