pandas.Index.sort_values

pandas 3.1.1 · Index objects · method

Order items by one or more data values, controlling missing-value placement.

Call syntax

Index.sort_values(*, return_indexer=False, ascending=True, na_position='last', key=None)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
return_indexer Optional
Keyword only
Default False
bool
ascending Optional
Keyword only
Default True
bool

Choose ascending or descending order. Some sorting methods take one flag per sort key.

na_position Optional
Keyword only
Default 'last'
{'first' or 'last'}

Place missing values first or last in the result.

key Optional
Keyword only
Default None
callable

Provide the lookup key, or a transformation callable for a sorting method.

Returns

sorted_index · pandas.Index; indexer · numpy.ndarray, optional