pyspark.sql.functions.locate¶
-
pyspark.sql.functions.
locate
(substr: str, str: ColumnOrName, pos: int = 1) → pyspark.sql.column.Column¶ Locate the position of the first occurrence of substr in a string column, after position pos.
- Parameters
- substrstr
a string
- str
Column
or str a Column of
pyspark.sql.types.StringType
- posint, optional
start position (zero based)
Notes
The position is not zero based, but 1 based index. Returns 0 if substr could not be found in str.
Examples
>>> df = spark.createDataFrame([('abcd',)], ['s',]) >>> df.select(locate('b', df.s, 1).alias('s')).collect() [Row(s=2)]