cudf.Series.sort_index#

Series.sort_index(axis=0, *args, **kwargs)#

Sort object by labels (along an axis).

Parameters:
axis{0 or ‘index’, 1 or ‘columns’}, default 0

The axis along which to sort. The value 0 identifies the rows, and 1 identifies the columns.

levelint or level name or list of ints or list of level names

If not None, sort on values in specified index level(s). This is only useful in the case of MultiIndex.

ascendingbool, default True

Sort ascending vs. descending.

inplacebool, default False

If True, perform operation in-place.

kindsorting method such as quick sort and others.

Not yet supported.

na_position{‘first’, ‘last’}, default ‘last’

Puts NaNs at the beginning if first; last puts NaNs at the end.

sort_remainingbool, default True

When sorting a multiindex on a subset of its levels, should entries be lexsorted by the remaining (non-specified) levels as well?

ignore_indexbool, default False

if True, index will be replaced with RangeIndex.

keycallable, optional

If not None, apply the key function to the index values before sorting. This is similar to the key argument in the builtin sorted() function, with the notable difference that this key function should be vectorized. It should expect an Index and return an Index of the same shape. For MultiIndex inputs, the key is applied per level.

Returns:
Frame or None

Examples

Series

>>> import cudf
>>> series = cudf.Series(['a', 'b', 'c', 'd'], index=[3, 2, 1, 4])
>>> series
3    a
2    b
1    c
4    d
dtype: object
>>> series.sort_index()
1    c
2    b
3    a
4    d
dtype: object

Sort Descending

>>> series.sort_index(ascending=False)
4    d
3    a
2    b
1    c
dtype: object

DataFrame

>>> df = cudf.DataFrame(
... {"b":[3, 2, 1], "a":[2, 1, 3]}, index=[1, 3, 2])
>>> df.sort_index(axis=0)
   b  a
1  3  2
2  1  3
3  2  1
>>> df.sort_index(axis=1)
   a  b
1  2  3
3  1  2
2  3  1

Pandas Compatibility Note

DataFrame.sort_index, Series.sort_index

  • Not supporting: kind, sort_remaining=False