Pandas DataFrame: sort_values() function
DataFrame - sort_values() function
The sort_values() function is used to sort by the values along either axis.
Syntax:
DataFrame.sort_values(self, by, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last')
Parameters:
Name | Description | Type/Default Value | Required / Optional |
---|---|---|---|
by | Name or list of names to sort by.
|
str or list of str | Required |
axis | Axis to be sorted. | {0 or ‘index’, 1 or ‘columns’} Default Value: 0 |
Required |
ascending | Sort ascending vs. descending. Specify list for multiple sort orders. If this is a list of bools, must match the length of the by. | bool or list of bool Default Value: True |
Required |
inplace | If True, perform operation in-place. | bool Default Value: False |
Required |
kind | Choice of sorting algorithm. See also ndarray.np.sort for more information. mergesort is the only stable algorithm. For DataFrames, this option is only applied when sorting on a single column or label. | {‘quicksort’, ‘mergesort’, ‘heapsort’} Default Value: ‘quicksort’ |
Required |
na_position | Puts NaNs at the beginning if first; last puts NaNs at the end. | {‘first’, ‘last’} Default Value: ‘last’ |
Required |
Returns: sorted_obj - DataFrame or None DataFrame with sorted values if inplace=False, None otherwise.
Example:
Download the Pandas DataFrame Notebooks from here.
Previous: DataFrame - pivot_table() function
Next: DataFrame - nlargest() function
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/pandas/dataframe/dataframe-sort_values.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics