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')
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
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework