pandas.DataFrame.sort_values
pandas 3.1.1 · DataFrame · method
Order items by one or more data values, controlling missing-value placement.
Call syntax
DataFrame.sort_values(…) Full signature
DataFrame.sort_values(
by,
*,
axis=0,
ascending=True,
inplace=…,
kind='quicksort',
na_position='last',
ignore_index=False,
key=None,
)Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
by |
Required Positional or keyword |
str or list of str Supply one or more column labels for a row sort, or row labels for a column sort. |
axis |
Optional Keyword only Default 0 |
"{0 or 'index', 1 or 'columns'}" Choose which axis the operation acts on. The accepted axis labels depend on the receiver. |
ascending |
Optional Keyword only Default True |
bool or list of bool Choose ascending or descending order. Some sorting methods take one flag per sort key. |
inplace |
Optional Keyword only |
bool Choose whether to change the existing object. Where supported, an in-place call typically returns None. |
kind |
Optional Keyword only Default 'quicksort' |
{'quicksort', 'mergesort', 'heapsort', 'stable'} Choose the implementation variant, such as a sort algorithm or a plot type. |
na_position |
Optional Keyword only Default 'last' |
{'first', 'last'} Place missing values first or last in the result. |
ignore_index |
Optional Keyword only Default False |
bool Give the resulting axis new integer labels where supported. |
key |
Optional Keyword only Default None |
callable Supply a vectorized function that takes a Series and returns a same-shape Series used for sorting. |
Returns
DataFrame or None