pandas.Series.str.find#
- Series.str.find(sub, start=0, end=None)[源代码]#
返回 Series/Index 中每个字符串的最低索引。
返回的每个索引对应于子字符串完全包含在 [start:end] 之间的位置。失败时返回 -1。等同于标准的
str.find()。- Parameters:
- substr
要搜索的子字符串。
- startint
左边缘索引。
- endint
右边缘索引。
- Returns:
- int 类型的 Series 或 Index。
参见
rfind返回每个字符串的最高索引。
Examples
对于 Series.str.find:
>>> ser = pd.Series(["cow_", "duck_", "do_ve"]) >>> ser.str.find("_") 0 3 1 4 2 2 dtype: int64
对于 Series.str.rfind:
>>> ser = pd.Series(["_cow_", "duck_", "do_v_e"]) >>> ser.str.rfind("_") 0 4 1 4 2 4 dtype: int64