@@ -2344,7 +2344,46 @@ def asof_locs(self, where, mask):
2344
2344
2345
2345
def sort_values (self , return_indexer = False , ascending = True ):
2346
2346
"""
2347
- Return sorted copy of Index
2347
+ Return a sorted copy of the index.
2348
+
2349
+ Return a sorted copy of the index, and optionally return the indices
2350
+ that sorted the index itself.
2351
+
2352
+ Parameters
2353
+ ----------
2354
+ return_indexer : bool, default False
2355
+ Should the indices that would sort the index be returned.
2356
+ ascending : bool, default True
2357
+ Should the index values be sorted in an ascending order.
2358
+
2359
+ Returns
2360
+ -------
2361
+ sorted_index : pandas.Index
2362
+ Sorted copy of the index.
2363
+ indexer : numpy.ndarray, optional
2364
+ The indices that the index itself was sorted by.
2365
+
2366
+ See Also
2367
+ --------
2368
+ pandas.Series.sort_values : Sort values of a Series.
2369
+ pandas.DataFrame.sort_values : Sort values in a DataFrame.
2370
+
2371
+ Examples
2372
+ --------
2373
+ >>> idx = pd.Index([10, 100, 1, 1000])
2374
+ >>> idx
2375
+ Int64Index([10, 100, 1, 1000], dtype='int64')
2376
+
2377
+ Sort values in ascending order (default behavior).
2378
+
2379
+ >>> idx.sort_values()
2380
+ Int64Index([1, 10, 100, 1000], dtype='int64')
2381
+
2382
+ Sort values in descending order, and also get the indices `idx` was
2383
+ sorted by.
2384
+
2385
+ >>> idx.sort_values(ascending=False, return_indexer=True)
2386
+ (Int64Index([1000, 100, 10, 1], dtype='int64'), array([3, 1, 0, 2]))
2348
2387
"""
2349
2388
_as = self .argsort ()
2350
2389
if not ascending :
0 commit comments