pandas 1.4.2

ParametersReturns
sortlevel(self, level=0, ascending: 'bool' = True, sort_remaining: 'bool' = True) -> 'tuple[MultiIndex, npt.NDArray[np.intp]]'

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

Parameters

level : list-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.

ascending : bool, default True

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

sort_remaining : sort by the remaining levels after level

Returns

sorted_index : pd.MultiIndex

Resulting index.

indexer : np.ndarray[np.intp]

Indices of output values in original index.

Sort MultiIndex at the requested level.

Examples

This example is valid syntax, but we were not able to check execution
>>> mi = pd.MultiIndex.from_arrays([[0, 0], [2, 1]])
... mi MultiIndex([(0, 2), (0, 1)], )
This example is valid syntax, but we were not able to check execution
>>> mi.sortlevel()
(MultiIndex([(0, 1),
            (0, 2)],
           ), array([1, 0]))
This example is valid syntax, but we were not able to check execution
>>> mi.sortlevel(sort_remaining=False)
(MultiIndex([(0, 2),
            (0, 1)],
           ), array([0, 1]))
This example is valid syntax, but we were not able to check execution
>>> mi.sortlevel(1)
(MultiIndex([(0, 1),
            (0, 2)],
           ), array([1, 0]))
This example is valid syntax, but we were not able to check execution
>>> mi.sortlevel(1, ascending=False)
(MultiIndex([(0, 2),
            (0, 1)],
           ), array([0, 1]))
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/indexes/multi.py#2404
type: <class 'function'>
Commit: