pandas.Series.str.index
- Series.str.index(sub, start=0, end=None)[source]
-
Return lowest indexes in each string in Series/Index.
Each of the returned indexes corresponds to the position where the substring is fully contained between [start:end]. This is the same as
str.find
except instead of returning -1, it raises a ValueError when the substring is not found. Equivalent to standardstr.index
.- Parameters:
-
- sub:str
-
Substring being searched.
- start:int
-
Left edge index.
- end:int
-
Right edge index.
- Returns:
-
- Series or Index of object
See also
rindex
-
Return highest indexes in each strings.
Examples
For Series.str.index:
>>> ser = pd.Series(["horse", "eagle", "donkey"]) >>> ser.str.index("e") 0 4 1 0 2 4 dtype: int64
For Series.str.rindex:
>>> ser = pd.Series(["Deer", "eagle", "Sheep"]) >>> ser.str.rindex("e") 0 2 1 4 2 3 dtype: int64
© 2008–2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
© 2011–2025, Open source contributors
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/2.3.0/reference/api/pandas.Series.str.index.html