cudf.core.column.lists.ListMethods.get#

ListMethods.get(index: int, default: Optional[Any] = None) Union[Series, GenericIndex]#

Extract element at the given index from each list in a Series of lists.

index can be an integer or a sequence of integers. If index is an integer, the element at position index is extracted from each list. If index is a sequence, it must be of the same length as the Series, and index[i] specifies the position of the element to extract from the i-th list in the Series.

If the index is out of bounds for any list, return <NA> or, if provided, default. Thus, this method never raises an IndexError.

Parameters
indexint or sequence of ints
defaultscalar, optional
Returns
Series or Index

Examples

>>> s = cudf.Series([[1, 2, 3], [3, 4, 5], [4, 5, 6]])
>>> s.list.get(-1)
0    3
1    5
2    6
dtype: int64
>>> s = cudf.Series([[1, 2], [3, 4, 5], [4, 5, 6]])
>>> s.list.get(2)
0    <NA>
1       5
2       6
dtype: int64
>>> s.list.get(2, default=0)
0   0
1   5
2   6
dtype: int64
>>> s.list.get([0, 1, 2])
0   1
1   4
2   6
dtype: int64