Index.
sort_values
Return a sorted copy of the index.
Return a sorted copy of the index, and optionally return the indices that sorted the index itself.
Should the indices that would sort the index be returned.
Should the index values be sorted in an ascending order.
Argument ‘first’ puts NaNs at the beginning, ‘last’ puts NaNs at the end.
New in version 1.2.0.
If not None, apply the key function to the index values before sorting. This is similar to the key argument in the builtin sorted() function, with the notable difference that this key function should be vectorized. It should expect an Index and return an Index of the same shape.
sorted()
Index
New in version 1.1.0.
Sorted copy of the index.
The indices that the index itself was sorted by.
See also
Series.sort_values
Sort values of a Series.
DataFrame.sort_values
Sort values in a DataFrame.
Examples
>>> idx = pd.Index([10, 100, 1, 1000]) >>> idx Int64Index([10, 100, 1, 1000], dtype='int64')
Sort values in ascending order (default behavior).
>>> idx.sort_values() Int64Index([1, 10, 100, 1000], dtype='int64')
Sort values in descending order, and also get the indices idx was sorted by.
>>> idx.sort_values(ascending=False, return_indexer=True) (Int64Index([1000, 100, 10, 1], dtype='int64'), array([3, 1, 0, 2]))