From eea12449e1d9f86a003fe1580dfddf4000d1c038 Mon Sep 17 00:00:00 2001 From: Farhan Reynaldo Date: Sat, 21 Mar 2020 13:00:31 +0700 Subject: [PATCH] DOC: Fix errors in pandas.DataFrame.sort_index --- pandas/core/frame.py | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index d1ba85c50d91d..84a601fa9d6cf 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -4824,6 +4824,9 @@ def sort_index( """ Sort object by labels (along an axis). + Returns a new DataFrame sorted by label if `inplace` argument is + ``False``, otherwise updates the original DataFrame and returns None. + Parameters ---------- axis : {0 or 'index', 1 or 'columns'}, default 0 @@ -4854,8 +4857,37 @@ def sort_index( Returns ------- - sorted_obj : DataFrame or None - DataFrame with sorted index if inplace=False, None otherwise. + DataFrame + The original DataFrame sorted by the labels. + + See Also + -------- + Series.sort_index : Sort Series by the index. + DataFrame.sort_values : Sort DataFrame by the value. + Series.sort_values : Sort Series by the value. + + Examples + -------- + >>> 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 """ # TODO: this can be combined with Series.sort_index impl as # almost identical