You are viewing documentation about an older version (1.21.0). View latest version

modin.pandas.Series.sort_values¶

Series.sort_values(axis: Axis = 0, ascending: bool | int | Sequence[bool] | Sequence[int] = True, inplace: bool = False, kind: str = 'quicksort', na_position: str = 'last', ignore_index: bool = False, key: IndexKeyFunc | None = None)[source]¶

Sort by the values.

Sort a Series in ascending or descending order by some criterion.

Parameters:
  • axis ({0 or 'index'}) – Unused. Parameter needed for compatibility with DataFrame.

  • ascending (bool or list of bools, default True) – If True, sort values in ascending order, otherwise descending.

  • inplace (bool, default False) – If True, perform operation in-place.

  • kind ({'quicksort', 'mergesort', 'heapsort', 'stable'} default 'None') – Choice of sorting algorithm. By default, Snowpark Pandaas performs unstable sort. Please use ‘stable’ to perform stable sort. Other choices ‘quicksort’, ‘mergesort’ and ‘heapsort’ are ignored.

  • na_position ({'first' or 'last'}, default 'last') – Argument ‘first’ puts NaNs at the beginning, ‘last’ puts NaNs at the end.

  • ignore_index (bool, default False) – If True, the resulting axis will be labeled 0, 1, …, n - 1.

  • key (callable, optional) – If not None, apply the key function to the series 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 a Series and return an array-like.

Returns:

Series ordered by values or None if inplace=True.

Return type:

Series or None

Notes

Snowpark pandas API doesn’t currently support distributed computation of sort_values when ‘key’ argument is provided.

See also

Series.sort_index

Sort by the Series indices.

DataFrame.sort_values

Sort DataFrame by the values along either axis.

DataFrame.sort_index

Sort DataFrame by indices.

Examples

>>> s = pd.Series([np.nan, 1, 3, 10, 5])
>>> s
0     NaN
1     1.0
2     3.0
3    10.0
4     5.0
dtype: float64
Copy

Sort values ascending order (default behaviour)

>>> s.sort_values(ascending=True)
1     1.0
2     3.0
4     5.0
3    10.0
0     NaN
dtype: float64
Copy

Sort values descending order

>>> s.sort_values(ascending=False)
3    10.0
4     5.0
2     3.0
1     1.0
0     NaN
dtype: float64
Copy

Sort values inplace

>>> s.sort_values(ascending=False, inplace=True)
>>> s
3    10.0
4     5.0
2     3.0
1     1.0
0     NaN
dtype: float64
Copy

Sort values putting NAs first

>>> s.sort_values(na_position='first')
0     NaN
1     1.0
2     3.0
4     5.0
3    10.0
dtype: float64
Copy

Sort a series of strings

>>> s = pd.Series(['z', 'b', 'd', 'a', 'c'])
>>> s
0    z
1    b
2    d
3    a
4    c
dtype: object
Copy
>>> s.sort_values()
3    a
1    b
4    c
2    d
0    z
dtype: object
Copy

Sort using a key function. Your key function will be given the Series of values and should return an array-like.

>>> s = pd.Series(['a', 'B', 'c', 'D', 'e'])
>>> s.sort_values()
1    B
3    D
0    a
2    c
4    e
dtype: object
Copy