pandas.Index.argsort#
- Index.argsort(*args, **kwargs)[source]#
Return the integer indices that would sort the index.
This method returns an array of indices that indicate the order in which elements of the index should be arranged to produce a sorted index. It delegates to the underlying array’s
argsortmethod.- Parameters:
- *args
Passed to numpy.ndarray.argsort.
- **kwargs
Passed to numpy.ndarray.argsort.
- Returns:
- np.ndarray[np.intp]
Integer indices that would sort the index if used as an indexer.
See also
numpy.argsortSimilar method for NumPy arrays.
Index.sort_valuesReturn sorted copy of Index.
Examples
>>> idx = pd.Index(["b", "a", "d", "c"]) >>> idx Index(['b', 'a', 'd', 'c'], dtype='str')
>>> order = idx.argsort() >>> order array([1, 0, 3, 2])
>>> idx[order] Index(['a', 'b', 'c', 'd'], dtype='str')