pyspark.sql.functions.
locate
Locate the position of the first occurrence of substr in a string column, after position pos.
Note
The position is not zero based, but 1 based index. Returns 0 if substr could not be found in str.
substr – a string
str – a Column of pyspark.sql.types.StringType
pyspark.sql.types.StringType
pos – start position (zero based)
>>> df = spark.createDataFrame([('abcd',)], ['s',]) >>> df.select(locate('b', df.s, 1).alias('s')).collect() [Row(s=2)]
New in version 1.5.