diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index fd1d3690e8a89..5edb031c7442c 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2316,16 +2316,38 @@ def shift(self, periods=1, freq=None): def argsort(self, *args, **kwargs): """ - Returns the indices that would sort the index and its - underlying data. + Return the integer indicies that would sort the index. + + Parameters + ---------- + *args + Passed to `numpy.ndarray.argsort`. + **kwargs + Passed to `numpy.ndarray.argsort`. Returns ------- - argsorted : numpy array + numpy.ndarray + Integer indicies that would sort the index if used as + an indexer. See also -------- - numpy.ndarray.argsort + numpy.argsort : Similar method for NumPy arrays. + Index.sort_values : Return sorted copy of Index. + + Examples + -------- + >>> idx = pd.Index(['b', 'a', 'd', 'c']) + >>> idx + Index(['b', 'a', 'd', 'c'], dtype='object') + + >>> order = idx.argsort() + >>> order + array([1, 0, 3, 2]) + + >>> idx[order] + Index(['a', 'b', 'c', 'd'], dtype='object') """ result = self.asi8 if result is None: