pyspark.sql.functions.position#

pyspark.sql.functions.position(substr, str, start=None)[source]#

Returns the position of the first occurrence of substr in str after position start. The given start and return value are 1-based.

New in version 3.5.0.

Parameters
substrColumn or str

A column of string, substring.

strColumn or str

A column of string.

startColumn or str, optional

A column of string, start position.

Examples

>>> import pyspark.sql.functions as sf
>>> spark.createDataFrame(
...     [("bar", "foobarbar", 5,)], ["a", "b", "c"]
... ).select(sf.position("a", "b", "c")).show()
+-----------------+
|position(a, b, c)|
+-----------------+
|                7|
+-----------------+
>>> spark.createDataFrame(
...     [("bar", "foobarbar", 5,)], ["a", "b", "c"]
... ).select(sf.position("a", "b")).show()
+-----------------+
|position(a, b, 1)|
+-----------------+
|                4|
+-----------------+