cudf.core.column.string.StringMethods.slice#
- StringMethods.slice(start: int | None = None, stop: int | None = None, step: int | None = None) SeriesOrIndex[source]#
从Series或Index中的每个元素中切片子字符串。
- Parameters:
- startint, optional
切片操作的起始位置。
- stopint, optional
切片操作的停止位置。
- stepint, optional
切片操作的步长。
- Returns:
- Series/Index of str dtype
从原始字符串对象中切片的子字符串生成的Series或Index。
另请参阅
slice_replace用字符串替换切片。
get返回指定位置的元素。等同于使用
Series.str.slice(start=i, stop=i+1),其中i为位置。
示例
>>> import cudf >>> s = cudf.Series(["koala", "fox", "chameleon"]) >>> s 0 koala 1 fox 2 chameleon dtype: object >>> s.str.slice(start=1) 0 oala 1 ox 2 hameleon dtype: object >>> s.str.slice(start=-1) 0 a 1 x 2 n dtype: object >>> s.str.slice(stop=2) 0 ko 1 fo 2 ch dtype: object >>> s.str.slice(step=2) 0 kaa 1 fx 2 caeen dtype: object >>> s.str.slice(start=0, stop=5, step=3) 0 kl 1 f 2 cm dtype: object