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 above Notebook from here.



Inviting useful, relevant, well-written and unique guest posts