Skip to content

Commit f78b1cc

Browse files
DOC: Fix errors in pandas.DataFrame.sort_index (#32880)
1 parent 72d833b commit f78b1cc

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

pandas/core/frame.py

+34-2
Original file line numberDiff line numberDiff line change
@@ -4824,6 +4824,9 @@ def sort_index(
48244824
"""
48254825
Sort object by labels (along an axis).
48264826
4827+
Returns a new DataFrame sorted by label if `inplace` argument is
4828+
``False``, otherwise updates the original DataFrame and returns None.
4829+
48274830
Parameters
48284831
----------
48294832
axis : {0 or 'index', 1 or 'columns'}, default 0
@@ -4854,8 +4857,37 @@ def sort_index(
48544857
48554858
Returns
48564859
-------
4857-
sorted_obj : DataFrame or None
4858-
DataFrame with sorted index if inplace=False, None otherwise.
4860+
DataFrame
4861+
The original DataFrame sorted by the labels.
4862+
4863+
See Also
4864+
--------
4865+
Series.sort_index : Sort Series by the index.
4866+
DataFrame.sort_values : Sort DataFrame by the value.
4867+
Series.sort_values : Sort Series by the value.
4868+
4869+
Examples
4870+
--------
4871+
>>> df = pd.DataFrame([1, 2, 3, 4, 5], index=[100, 29, 234, 1, 150],
4872+
... columns=['A'])
4873+
>>> df.sort_index()
4874+
A
4875+
1 4
4876+
29 2
4877+
100 1
4878+
150 5
4879+
234 3
4880+
4881+
By default, it sorts in ascending order, to sort in descending order,
4882+
use ``ascending=False``
4883+
4884+
>>> df.sort_index(ascending=False)
4885+
A
4886+
234 3
4887+
150 5
4888+
100 1
4889+
29 2
4890+
1 4
48594891
"""
48604892
# TODO: this can be combined with Series.sort_index impl as
48614893
# almost identical

0 commit comments

Comments
 (0)