pyspark.pandas.MultiIndex.swaplevel

MultiIndex.swaplevel(i: int = - 2, j: int = - 1) → pyspark.pandas.indexes.multi.MultiIndex

Swap level i with level j. Calling this method does not change the ordering of the values.

Parameters
iint, str, default -2

First level of index to be swapped. Can pass level name as string. Type of parameters can be mixed.

jint, str, default -1

Second level of index to be swapped. Can pass level name as string. Type of parameters can be mixed.

Returns
MultiIndex

A new MultiIndex.

Examples

>>> midx = ps.MultiIndex.from_arrays([['a', 'b'], [1, 2]], names = ['word', 'number'])
>>> midx  
MultiIndex([('a', 1),
            ('b', 2)],
           names=['word', 'number'])
>>> midx.swaplevel(0, 1)  
MultiIndex([(1, 'a'),
            (2, 'b')],
           names=['number', 'word'])
>>> midx.swaplevel('number', 'word')  
MultiIndex([(1, 'a'),
            (2, 'b')],
           names=['number', 'word'])