pandas.Series.str.rindex#
- Series.str.rindex(sub, start=0, end=None)[源代码]#
返回 Series/Index 中每个字符串的最高索引。
返回的每个索引对应于子字符串完全包含在 [start:end] 之间的位置。这与
str.rfind相同,只是它在找不到子字符串时会引发 ValueError,而不是返回 -1。等效于标准的str.rindex。- Parameters:
- substr
要搜索的子字符串。
- startint
左边缘索引。
- endint
右边缘索引。
- Returns:
- Series 或 Index 对象
参见
index返回每个字符串的最低索引。
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