pandas.DataFrame.sort_index¶
- DataFrame.sort_index(axis=0, by=None, ascending=True, inplace=False, kind='quicksort', na_position='last')¶
Sort DataFrame either by labels (along either axis) or by the values in a column
Parameters: axis : {0, 1}
Sort index/rows versus columns
by : object
Column name(s) in frame. Accepts a column name or a list for a nested sort. A tuple will be interpreted as the levels of a multi-index.
ascending : boolean or list, default True
Sort ascending vs. descending. Specify list for multiple sort orders
inplace : boolean, default False
Sort the DataFrame without creating a new instance
na_position : {‘first’, ‘last’} (optional, default=’last’)
‘first’ puts NaNs at the beginning ‘last’ puts NaNs at the end
kind : {‘quicksort’, ‘mergesort’, ‘heapsort’}, optional
This option is only applied when sorting on a single column or label.
Returns: sorted : DataFrame
Examples
>>> result = df.sort_index(by=['A', 'B'], ascending=[True, False])