maxframe.dataframe.Series.str.slice#
- Series.str.slice(start=None, stop=None, step=None)#
从 Series 或 Index 的每个元素中切片出子字符串。
Slicing substrings from strings in a Series or Index helps extract specific portions of data, making it easier to analyze or manipulate text. This is useful for tasks like parsing structured text fields or isolating parts of strings with a consistent format.
- 参数:
- 返回:
从原始字符串对象中切片出的子字符串组成的 Series 或 Index。
- 返回类型:
参见
Series.str.slice_replace用字符串替换一个切片。
Series.str.get返回指定位置的元素。等价于 Series.str.slice(start=i, stop=i+1),其中 i 是位置。
示例
>>> import maxframe.dataframe as md >>> s = md.Series(["koala", "dog", "chameleon"]) >>> s.execute() 0 koala 1 dog 2 chameleon dtype: str
>>> s.str.slice(start=1).execute() 0 oala 1 og 2 hameleon dtype: str
>>> s.str.slice(start=-1).execute() 0 a 1 g 2 n dtype: str
>>> s.str.slice(stop=2).execute() 0 ko 1 do 2 ch dtype: str
>>> s.str.slice(step=2).execute() 0 kaa 1 dg 2 caeen dtype: str
>>> s.str.slice(start=0, stop=5, step=3).execute() 0 kl 1 d 2 cm dtype: str
等效行为:
>>> s.str[0:5:3].execute() 0 kl 1 d 2 cm dtype: str