Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

Pandas Series: sort_values() function

Sort Pandas series in ascending or descending order by some criterion

The sort_values() function is used to sort by the values.

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

Syntax:

Series.sort_values(self, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last')
Pandas Series sort_values image

Parameters:

Name Description Type/Default Value Required / Optional
axis Axis to direct sorting. The value ‘index’ is accepted for compatibility with DataFrame.sort_values.  {0 or ‘index’}
Default Value: 0
Required
ascending If True, sort values in ascending order, otherwise descending. bool
Default Value: True
Required
inplace Sort ascending vs. descending. bool
Default Value: True
Required
inplace If True, perform operation in-place. bool
Default Value: False
Required
kind Choice of sorting algorithm. See also numpy.sort() for more information. ‘mergesort’ is the only stable algorithm. {‘quicksort’, ‘mergesort’ or ‘heapsort’}
Default Value: ‘quicksort’
Required
na_position Argument ‘first’ puts NaNs at the beginning, ‘last’ puts NaNs at the end. {‘first’ or ‘last’}
Default Value: ‘last’
Required

Returns: Series - Series ordered by values.

Example:


Download the Pandas Series Notebooks from here.

Previous: Fill NA/missing values in a Pandas series
Next: Sorts Pandas series by labels along the given axis