【发布时间】:2019-05-23 17:00:29
【问题描述】:
我有 2 个 spark 数据帧,我想根据以下条件将名为“seg”的新列添加到数据帧 df2
- 如果 df1.colx 中存在 df2.colx 值。
我在 pyspark 中尝试了以下操作,但它抛出异常。
cc002 = df2.withColumn('seg',F.when(df2.colx == df1.colx,"True").otherwise("FALSE"))
- df1:
id colx coly
1 678 56789
2 900 67890
3 789 67854
- df2
Name colx
seema 900
yash 678
deep 800
harsh 900
- 我的预期输出是
Name colx seg
seema 900 True
harsh 900 True
yash 678 True
deep 800 False
请帮助我更正给定的 pyspark 代码或提出更好的方法。
【问题讨论】:
标签: pyspark