pandas.Series.str.index#

Series.str.index(sub, start=0, end=None)[源代码]#

返回 Series/Index 中每个字符串中的最低索引。

返回的每个索引对应于子字符串完全包含在 [start:end] 之间的位置。这与 str.find 相同,但除了返回 -1,它在找不到子字符串时引发 ValueError。等同于标准的 str.index

Parameters:
substr

要搜索的子字符串。

startint

左边缘索引。

endint

右边缘索引。

Returns:
Series 或 Index 对象

参见

rindex

返回每个字符串的最高索引。

Examples

对于 Series.str.index:

>>> ser = pd.Series(["horse", "eagle", "donkey"])
>>> ser.str.index("e")
0   4
1   0
2   4
dtype: int64

对于 Series.str.rindex:

>>> ser = pd.Series(["Deer", "eagle", "Sheep"])
>>> ser.str.rindex("e")
0   2
1   4
2   3
dtype: int64