Use “IS IN” between 2 Spark dataframe columns

こ雲淡風輕ζ 提交于 2019-12-01 23:36:45

You can use array_contains:

from pyspark.sql.functions import expr

test.withColumn("isinlist", expr("array_contains(Animaux, Animal)")).show()
# +--------+---------------+------+--------+
# |ClientId|        Animaux|Animal|isinlist|
# +--------+---------------+------+--------+
# |     ALT|  [chien, chat]|oiseau|   false|
# |     ALT|       [oiseau]|oiseau|    true|
# |     TDR|[poule, poulet]| poule|    true|
# |     ALT|         [ours]| chien|   false|
# |     ALT|         [paon]| tigre|   false|
# |     TDR|  [tigre, lion]|  lion|    true|
# |     ALT|         [chat]| chien|   false|
# +--------+---------------+------+--------+

Source How to filter Spark dataframe if one column is a member of another column by zero323 (Scala).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!