pyspark.sql.functions.find_in_set

pyspark.sql.functions.find_in_set(str: ColumnOrName, str_array: ColumnOrName) → pyspark.sql.column.Column[source]

Returns the index (1-based) of the given string (str) in the comma-delimited list (strArray). Returns 0, if the string was not found or if the given string (str) contains a comma.

New in version 3.5.0.

Parameters
strColumn or str

The given string to be found.

str_arrayColumn or str

The comma-delimited list.

Examples

>>> df = spark.createDataFrame([("ab", "abc,b,ab,c,def")], ['a', 'b'])
>>> df.select(find_in_set(df.a, df.b).alias('r')).collect()
[Row(r=3)]