- API reference
- Series
- pandas.Serie...
pandas.Series.str.slice#
- Series.str.slice(start=None,stop=None,step=None)[source]#
Slice substrings from each element in the Series or Index.
- Parameters:
- startint, optional
Start position for slice operation.
- stopint, optional
Stop position for slice operation.
- stepint, optional
Step size for slice operation.
- Returns:
- Series or Index of object
Series or Index from sliced substring from original string object.
See also
Series.str.slice_replaceReplace a slice with a string.
Series.str.getReturn element at position. Equivalent toSeries.str.slice(start=i, stop=i+1) withi being the position.
Examples
>>>s=pd.Series(["koala","dog","chameleon"])>>>s0 koala1 dog2 chameleondtype: object
>>>s.str.slice(start=1)0 oala1 og2 hameleondtype: object
>>>s.str.slice(start=-1)0 a1 g2 ndtype: object
>>>s.str.slice(stop=2)0 ko1 do2 chdtype: object
>>>s.str.slice(step=2)0 kaa1 dg2 caeendtype: object
>>>s.str.slice(start=0,stop=5,step=3)0 kl1 d2 cmdtype: object
Equivalent behaviour to:
>>>s.str[0:5:3]0 kl1 d2 cmdtype: object
On this page