I'm a newbie in pyspark and I'm looking for finding a column1 item in column2 list of items. Let's have an example.
Let's have an easy example with google search - 3 columns - query - string, hrefs - list and clicked_url - string and I need to check if clicked_url is in hrefs.
There are 3 possible scenarios that can occur:
If clicked_url is in hrefs list THEN keep the row
If clicked_url is not in hrefs list THEN filter out that row -remove. (you can imagine that as a click on advertisement)
If clicked_url is empty (there was no clicked_url) THEN keep the row but change the value of clicked_url to 0.
query | hrefs | clicked_url
------------------------------------
car |[url1,...url10] | url1
monkey |[url11,...url20]| url11
mouse |[url21,...url30]| url11
donkey |[url31,...url40]| "" - empty string
ball |[url41,...url50]| url45
monkey |[url11,...url20]| url1
Desired output:
query | hrefs | clicked_url
------------------------------------
car |[url1,...url10] | url1
monkey |[url11,...url20]| url11
donkey |[url31,...url40]| 0
ball |[url41,...url50]| url45
Thanks in advance!