MCPcopy
hub / github.com/pandas-dev/pandas / argsort

Method argsort

pandas/core/series.py:3963–4016  ·  view source on GitHub ↗

Return the integer indices that would sort the Series values. Override ndarray.argsort. Argsorts the value, omitting NA/null values, and places the result in the same locations as the non-NA values. Parameters ---------- axis : {0 or 'index'}

(
        self,
        axis: Axis = 0,
        kind: SortKind = "quicksort",
        order: None = None,
        stable: None = None,
    )

Source from the content-addressed store, hash-verified

3961 )
3962
3963 def argsort(
3964 self,
3965 axis: Axis = 0,
3966 kind: SortKind = "quicksort",
3967 order: None = None,
3968 stable: None = None,
3969 ) -> Series:
3970 """
3971 Return the integer indices that would sort the Series values.
3972
3973 Override ndarray.argsort. Argsorts the value, omitting NA/null values,
3974 and places the result in the same locations as the non-NA values.
3975
3976 Parameters
3977 ----------
3978 axis : {0 or 'index'}
3979 Unused. Parameter needed for compatibility with DataFrame.
3980 kind : {'mergesort', 'quicksort', 'heapsort', 'stable'}, default 'quicksort'
3981 Choice of sorting algorithm. See :func:`numpy.sort` for more
3982 information. 'mergesort' and 'stable' are the only stable algorithms.
3983 order : None
3984 Has no effect but is accepted for compatibility with numpy.
3985 stable : None
3986 Has no effect but is accepted for compatibility with numpy.
3987
3988 Returns
3989 -------
3990 Series[np.intp]
3991 Positions of values within the sort order with -1 indicating
3992 nan values.
3993
3994 See Also
3995 --------
3996 numpy.ndarray.argsort : Returns the indices that would sort this array.
3997
3998 Examples
3999 --------
4000 >>> s = pd.Series([3, 2, 1])
4001 >>> s.argsort()
4002 0 2
4003 1 1
4004 2 0
4005 dtype: int64
4006 """
4007 if axis != -1:
4008 # GH#54257 We allow -1 here so that np.argsort(series) works
4009 self._get_axis_number(axis)
4010
4011 result = self.array.argsort(kind=kind)
4012
4013 res = self._constructor(
4014 result, index=self.index, name=self.name, dtype=np.intp, copy=False
4015 )
4016 return res.__finalize__(self, method="argsort")
4017
4018 def nlargest(
4019 self, n: int = 5, keep: Literal["first", "last", "all"] = "first"

Callers 15

test_argsort_axisMethod · 0.95
test_argsort_dt64Method · 0.95
test_argsort_stableMethod · 0.95
time_argsortMethod · 0.45
assert_is_sortedFunction · 0.45
safe_sortFunction · 0.45
_sort_mixedFunction · 0.45
nargsortFunction · 0.45
get_group_index_sorterFunction · 0.45
_reorder_by_uniquesFunction · 0.45
_interpolate_1dFunction · 0.45

Calls 3

_constructorMethod · 0.95
_get_axis_numberMethod · 0.80
__finalize__Method · 0.80

Tested by 15

test_argsort_axisMethod · 0.76
test_argsort_dt64Method · 0.76
test_argsort_stableMethod · 0.76
test_numpy_argsortMethod · 0.36
test_argsort_numpyMethod · 0.36
test_argsortMethod · 0.36
test_argsort_with_naMethod · 0.36
test_sort_valuesMethod · 0.36