pyspark.sql.functions.
array_position
Collection function: Locates the position of the first occurrence of the given value in the given array. Returns null if either of the arguments are null.
New in version 2.4.0.
Notes
The position is not zero based, but 1 based index. Returns 0 if the given value could not be found in the array.
Examples
>>> df = spark.createDataFrame([(["c", "b", "a"],), ([],)], ['data']) >>> df.select(array_position(df.data, "a")).collect() [Row(array_position(data, a)=3), Row(array_position(data, a)=0)]