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.

Added in version 3.5.0.

Parameters:
substrColumn or str

A column of string, substring. A column that evaluates to a string.

strColumn or str

A column of string. A column that evaluates to a string.

startColumn or str, optional

The start position. A column that evaluates to an integer.

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|
+-----------------+