modin.pandas.Index.sort_values¶
- Index.sort_values(return_indexer: bool = False, ascending: bool = True, na_position: NaPosition = 'last', key: Callable | None = None) Index | tuple[Index, np.ndarray] [source] (https://github.com/snowflakedb/snowpark-python/blob/v1.26.0/snowpark-python/src/snowflake/snowpark/modin/plugin/extensions/index.py#L801-L830)¶
Return a sorted copy of the index.
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 ascending order.
na_position ({'first' or 'last'}, default 'last') – Argument ‘first’ puts NaNs at the beginning, ‘last’ puts NaNs at the end.
key (callable, optional) – 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 anIndex
and return anIndex
of the same shape. This parameter is not yet supported.
- Returns:
Index is returned in all cases as a sorted copy of the index. ndarray is returned when return_indexer is True, represents the indices that the index itself was sorted by.
- Return type:
Index, numpy.ndarray
See also
Series.sort_values
Sort values of a Series.
DataFrame.sort_values
Sort values in a DataFrame.
Note
The order of the indexer pandas returns is based on numpy’s argsort which defaults to quicksort. However, currently Snowpark pandas does not support quicksort; instead, stable sort is performed. Therefore, the order of the indexer returned by Index.sort_values is not guaranteed to match pandas’ result indexer.
Examples
>>> idx = pd.Index([10, 100, 1, 1000]) >>> idx Index([10, 100, 1, 1000], dtype='int64')
Sort values in ascending order (default behavior).
>>> idx.sort_values() Index([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) (Index([1000, 100, 10, 1], dtype='int64'), array([3, 1, 0, 2]))