pyspark.pandas.Series.str.index

str. index ( sub : str , start : int = 0 , end : Optional [ int ] = None ) → pyspark.pandas.series.Series

返回每个字符串中子字符串完全包含在 [start:end] 之间的最低索引。

这与 str.find() 相同,只是当子字符串未找到时,它不会返回 -1,而是会引发 ValueError。等同于标准的 str.index()

Parameters
sub str

正在搜索的子字符串。

start int

左边缘索引。

end int

右侧边缘索引。

Returns
Series of int

最低匹配索引的序列。

示例

>>> s = ps.Series(['apple', 'oranges', 'bananas'])
>>> s.str.index('a')
0    0
1    2
2    1
dtype: int64

以下表达式会抛出一个异常:

>>> s.str.index('a', start=2)