pyspark.pandas.Series.str.slice#

str.slice(start=None, stop=None, step=None)#

Slice substrings from each element in the Series.

Parameters
startint, optional

Start position for slice operation.

stopint, optional

Stop position for slice operation.

stepint, optional

Step size for slice operation.

Returns
Series of object

Series from sliced substrings from original string objects.

Examples

>>> 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