I have a data frame that looks like this:
+-------+-------+--------------------+
| user| item| ls_rec_items|
+-------+-------+--------------------+
| 321| 3| [4, 3, 2, 6, 1, 5]|
| 123| 2| [5, 6, 3, 1, 2, 4]|
| 123| 7| [5, 6, 3, 1, 2, 4]|
+-------+-------+--------------------+
I want to know in which position the "item" is in the "ls_rec_items" array.
I know the function array_position, but I don't know how to get the "item" value there.
I know this:
df.select(F.array_position(df.ls_rec_items, 3)).collect()
But I want this:
df.select(F.array_position(df.ls_rec_items, df.item)).collect()
The output should look like this:
+-------+-------+--------------------+-----+
| user| item| ls_rec_items| pos|
+-------+-------+--------------------+-----+
| 321| 3| [4, 3, 2, 6, 1, 5]| 2|
| 123| 2| [5, 6, 3, 1, 2, 4]| 5|
| 123| 7| [5, 6, 3, 1, 2, 4]| 0|
+-------+-------+--------------------+-----+