![](/img/trans.png)
[英]How to join two dataframes in Scala and select on few columns from the dataframes by their index?
[英]Dataframes Join in Scala with multiple columns is not same with few columns might be null
我有2个数据框如下。
目标是从df2中找到一个新行,其中数据帧1中不存在相同的列值。
我试图以id作为联接条件联接两个数据框,并检查其他列值不等于如下。
但这行不通。
有人可以帮忙吗?
df1:此数据框就像一个主表
id amt city date
abc 100 City1 9/26/2018
abc 100 City1 9/25/2018
def 200 City2 9/26/2018
ghi 300 City3 9/26/2018
df2:每天都会出现一个新的数据集Dataframe 2。
id amt city date
abc 100 City1 9/27/2018
def null City2 9/26/2018
ghi 300 City3 9/26/2018
结果:提出如下结果数据框:
id amt city date
abc 100 City1 9/27/2018
def null City2 9/26/2018
我试过的代码:
val writeDF = df1.join(df2, df1.col("id") === df2.col("id")).
where(df1.col("amt") =!= df2.col("amt")).where(df1.col("city") =!=
df2.col("city")).where(df1.col("date") =!= df2.col("date")).select($"df2.*")
DataFrame方法df1.except(df2)
将返回df1
中所有不存在于df2
。
来源: Spark 2.2.0文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.