cudf.core.column.lists.ListMethods.sort_values#
- ListMethods.sort_values(ascending: bool = True, inplace: bool = False, kind: str = 'quicksort', na_position: Literal['first', 'last'] = 'last', ignore_index: bool = False) Series | Index [source]#
Sort each list by the values.
Sort the lists in ascending or descending order by some criterion.
- Parameters:
- ascendingbool, default True
If True, sort values in ascending order, otherwise descending.
- na_position{‘first’, ‘last’}, default ‘last’
‘first’ puts nulls at the beginning, ‘last’ puts nulls at the end.
- ignore_indexbool, default False
If True, the resulting axis will be labeled 0, 1, …, n - 1.
- Returns:
- Series or Index with each list sorted
Examples
>>> s = cudf.Series([[4, 2, None, 9], [8, 8, 2], [2, 1]]) >>> s.list.sort_values(ascending=True, na_position="last") 0 [2.0, 4.0, 9.0, nan] 1 [2.0, 8.0, 8.0] 2 [1.0, 2.0] dtype: list
Pandas Compatibility Note
pandas.Series.list.sort_values
This method does not exist in pandas but it can be run as:
>>> import pandas as pd >>> s = pd.Series([[3, 2, 1], [2, 4, 3]]) >>> print(s.apply(sorted)) 0 [1, 2, 3] 1 [2, 3, 4] dtype: object