pyspark.sql.functions.position¶
-
pyspark.sql.functions.
position
(substr: ColumnOrName, str: ColumnOrName, start: Optional[ColumnOrName] = None) → pyspark.sql.column.Column[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
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| +-----------------+