A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://pandas.pydata.org/pandas-docs/stable/reference/api/../api/pandas.MultiIndex.sortlevel.html below:

pandas.MultiIndex.sortlevel — pandas 2.3.1 documentation

pandas.MultiIndex.sortlevel#
MultiIndex.sortlevel(level=0, ascending=True, sort_remaining=True, na_position='first')[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.

ascendingbool, 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
na_position{‘first’ or ‘last’}, default ‘first’

Argument ‘first’ puts NaNs at the beginning, ‘last’ puts NaNs at the end.

Added in version 2.1.0.

Returns:
sorted_indexpd.MultiIndex

Resulting index.

indexernp.ndarray[np.intp]

Indices of output values in original index.

Examples

>>> mi = pd.MultiIndex.from_arrays([[0, 0], [2, 1]])
>>> mi
MultiIndex([(0, 2),
            (0, 1)],
           )
>>> mi.sortlevel()
(MultiIndex([(0, 1),
            (0, 2)],
           ), array([1, 0]))
>>> mi.sortlevel(sort_remaining=False)
(MultiIndex([(0, 2),
            (0, 1)],
           ), array([0, 1]))
>>> mi.sortlevel(1)
(MultiIndex([(0, 1),
            (0, 2)],
           ), array([1, 0]))
>>> mi.sortlevel(1, ascending=False)
(MultiIndex([(0, 2),
            (0, 1)],
           ), array([0, 1]))

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4