pandas 1.4.2

ParametersReturnsBackRef
sort_values(self, return_indexer: 'bool' = False, ascending: 'bool' = True, na_position: 'str_t' = 'last', key: 'Callable | None' = None)

Return a sorted copy of the index, and optionally return the indices that sorted the index itself.

Parameters

return_indexer : bool, default False

Should the indices that would sort the index be returned.

ascending : bool, default True

Should the index values be sorted in an ascending order.

na_position : {'first' or 'last'}, default 'last'

Argument 'first' puts NaNs at the beginning, 'last' puts NaNs at the end.

versionadded
key : callable, optional

If not None, apply the key function to the index values before sorting. This is similar to the :None:None:`key` argument in the builtin sorted function, with the notable difference that this :None:None:`key` function should be vectorized. It should expect an Index and return an Index of the same shape.

versionadded

Returns

sorted_index : pandas.Index

Sorted copy of the index.

indexer : numpy.ndarray, optional

The indices that the index itself was sorted by.

Return a sorted copy of the index.

See Also

DataFrame.sort_values

Sort values in a DataFrame.

Series.sort_values

Sort values of a Series.

Examples

This example is valid syntax, but we were not able to check execution
>>> idx = pd.Index([10, 100, 1, 1000])
... idx Int64Index([10, 100, 1, 1000], dtype='int64')

Sort values in ascending order (default behavior).

This example is valid syntax, but we were not able to check execution
>>> idx.sort_values()
Int64Index([1, 10, 100, 1000], dtype='int64')

Sort values in descending order, and also get the indices :None:None:`idx` was sorted by.

This example is valid syntax, but we were not able to check execution
>>> idx.sort_values(ascending=False, return_indexer=True)
(Int64Index([1000, 100, 10, 1], dtype='int64'), array([3, 1, 0, 2]))
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.indexes.base.Index.argsort

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/base.py#5404
type: <class 'function'>
Commit: