pandas.MultiIndex.sortlevel

MultiIndex.sortlevel(self, level=0, ascending=True, sort_remaining=True)[source]

Sort MultiIndex at the requested level. The result will respect the original ordering of the associated factor at that level.

Parameters
levellist-like, int or str, default 0

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

ascendingboolean, default True

False to sort in descending order Can also be a list to specify a directed ordering

sort_remainingsort by the remaining levels after level
Returns
sorted_indexpd.MultiIndex

Resulting index.

indexernp.ndarray

Indices of output values in original index.

Scroll To Top