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,
)
| 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" |