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. Ifindex
is an integer, the element at positionindex
is extracted from each list. Ifindex
is a sequence, it must be of the same length as the Series, andindex[i]
specifies the position of the element to extract from thei
-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 anIndexError
.- 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