Skip to content
Advertisement

Filter expected value from list in df column

I have a data frame with the following column:

JavaScript

I want to return a column with single value based on a conditional statement. I wrote the following function:

JavaScript

When running the function on the column df.withColumn("col", filter_func("raw_col")) I have the following error col should be Column

What’s wrong here? What should I do?

Advertisement

Answer

You can use array_contains function:

JavaScript

But if you have a complex logic and need necessary use the filter_func, it’s needed to create an UDF:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement