How to sort a pandas DataFrame or a Series ? | Pandas sort_values() | Pandas Tutorial for Beginners

Published: 20 July 2020
on channel: Engineers Revolution
146
3

pandas.DataFrame.sort_values
DataFrame.sort_values(self, by, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last', ignore_index=False)[source]
Sort by the values along either axis.

Parameters
by str or list of str
Name or list of names to sort by.

if axis is 0 or ‘index’ then by may contain index levels and/or column labels.

if axis is 1 or ‘columns’ then by may contain column levels and/or index labels.

Changed in version 0.23.0: Allow specifying index or column level names.

axis{0 or ‘index’, 1 or ‘columns’}, default 0
Axis to be sorted.

ascending bool or list of bool, default True
Sort ascending vs. descending. Specify list for multiple sort orders. If this is a list of bools, must match the length of the by.

inplace bool, default False
If True, perform operation in-place.

kind{‘quicksort’, ‘mergesort’, ‘heapsort’}, default ‘quicksort’
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.

na_position{‘first’, ‘last’}, default ‘last’
Puts NaNs at the beginning if first; last puts NaNs at the end.

ignore_index bool, default False
If True, the resulting axis will be labeled 0, 1, …, n - 1.

New in version 1.0.0.

Returns
sorted_obj DataFrame or None
DataFrame with sorted values if inplace=False, None otherwise.

The github link for this notebook is below 👇👇
https://github.com/RakeshKrishna143/P...


Watch video How to sort a pandas DataFrame or a Series ? | Pandas sort_values() | Pandas Tutorial for Beginners online without registration, duration hours minute second in high quality. This video was added by user Engineers Revolution 20 July 2020, don't forget to share it with your friends and acquaintances, it has been viewed on our site 146 once and liked it 3 people.