pandas.Series.sort_values¶
Sort by the values.
Sort a Series in ascending or descending order by some criterion.
- param axis
- {0 or ‘index’}, default 0
Axis to direct sorting. The value ‘index’ is accepted for compatibility with DataFrame.sort_values.
- param ascending
- bool, default True
If True, sort values in ascending order, otherwise descending.
- param inplace
- bool, default False
If True, perform operation in-place.
- param kind
- {‘quicksort’, ‘mergesort’ or ‘heapsort’}, default ‘quicksort’
Choice of sorting algorithm. See also
numpy.sort()
for more information. ‘mergesort’ is the only stable algorithm.
- param na_position
- {‘first’ or ‘last’}, default ‘last’
Argument ‘first’ puts NaNs at the beginning, ‘last’ puts NaNs at the end.
- return
Series Series ordered by values.
Limitations¶
Parameter
inplace
is supported only with default valueFalse
.Parameter
axis
is currently unsupported by Intel Scalable Dataframe Compiler.Parameter
kind
is supported only with values'mergesort'
and'quicksort'
.- This function may reveal slower performance than Pandas* on user system. Users should exercise a tradeoff
between staying in JIT-region with that function or going back to interpreter mode.
Examples¶
import numpy as np
import pandas as pd
from numba import njit
@njit
def series_sort_values():
series = pd.Series([3, -10, np.nan, 0, 92])
return series.sort_values()
print(series_sort_values())
$ python ./series/series_sort_values.py
1 -10.0
3 0.0
0 3.0
4 92.0
2 NaN
dtype: float64
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.