sort_index(self, axis: 'Axis' = 0, level: 'Level | None' = None, ascending: 'bool | int | Sequence[bool | int]' = True, inplace: 'bool' = False, kind: 'str' = 'quicksort', na_position: 'str' = 'last', sort_remaining: 'bool' = True, ignore_index: 'bool' = False, key: 'IndexKeyFunc' = None)
Returns a new DataFrame sorted by label if :None:None:`inplace`
argument is False
, otherwise updates the original DataFrame and returns None.
The axis along which to sort. The value 0 identifies the rows, and 1 identifies the columns.
If not None, sort on values in specified index level(s).
Sort ascending vs. descending. When the index is a MultiIndex the sort direction can be controlled for each level individually.
If True, perform operation in-place.
Choice of sorting algorithm. See also numpy.sort
for more information. :None:None:`mergesort`
and :None:None:`stable`
are the only stable algorithms. For DataFrames, this option is only applied when sorting on a single column or label.
Puts NaNs at the beginning if :None:None:`first`
; :None:None:`last`
puts NaNs at the end. Not implemented for MultiIndex.
If True and sorting by level and index is multilevel, sort by other levels too (in order) after sorting by specified level.
If True, the resulting axis will be labeled 0, 1, …, n - 1.
If not None, apply the key function to the index values before sorting. This is similar to the :None:None:`key`
argument in the builtin sorted
function, with the notable difference that this :None:None:`key`
function should be vectorized. It should expect an Index
and return an Index
of the same shape. For MultiIndex inputs, the key is applied per level.
The original DataFrame sorted by the labels or None if inplace=True
.
Sort object by labels (along an axis).
DataFrame.sort_values
Sort DataFrame by the value.
Series.sort_index
Sort Series by the index.
Series.sort_values
Sort Series by the value.
>>> df = pd.DataFrame([1, 2, 3, 4, 5], index=[100, 29, 234, 1, 150],
... columns=['A'])
... df.sort_index() A 1 4 29 2 100 1 150 5 234 3
By default, it sorts in ascending order, to sort in descending order, use ascending=False
>>> df.sort_index(ascending=False) A 234 3 150 5 100 1 29 2 1 4
A key function can be specified which is applied to the index before sorting. For a MultiIndex
this is applied to each level separately.
>>> df = pd.DataFrame({"a": [1, 2, 3, 4]}, index=['A', 'b', 'C', 'd'])See :
... df.sort_index(key=lambda x: x.str.lower()) a A 1 b 2 C 3 d 4
The following pages refer to to this document either explicitly or contain code examples using this.
pandas.core.series.Series.sort_values
pandas.core.generic.NDFrame.sort_values
pandas.core.series.Series.sort_index
pandas.core.frame.DataFrame.sort_values
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them