pyspark.pandas.Series.str.slice

str. slice ( start : Optional [ int ] = None , stop : Optional [ int ] = None , step : Optional [ int ] = None ) → pyspark.pandas.series.Series

从序列的每个元素中切片子字符串。

Parameters
start int, optional

切片操作的起始位置。

stop int, optional

切片操作的停止位置。

step int, optional

切片操作的步长。

Returns
Series of object

从原始字符串对象中切片子字符串得到的序列。

示例

>>> s = ps.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(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