Spark Scala将列从一个数据框复制到另一个数据框 [英] Spark Scala copy column from one dataframe to another

查看:44
本文介绍了Spark Scala将列从一个数据框复制到另一个数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个原始数据框的修改版本,在上面进行了聚类,现在,我想将预测列返回到原始DF(索引正常,因此匹配).我应该怎么做?有了这段代码,我得到一个错误.

I have a modified version of the original dataframe on which I did clustering, Now I want to bring the predicted column back to the original DF (the index is ok, so it matches). How am I supposed to do this? With this code I get an error.

println("Predicted:")
dfWithOutput.show
println("Original:")
originalDF = originalDF.withColumn("cluster", dfWithOutput.col("prediction")

Exception in thread "main" org.apache.spark.sql.AnalysisException: Resolved attribute(s) prediction#2121 missing from (list of columns in the original df)

推荐答案

您需要加入两个数据框,然后选择您感兴趣的列

you need to join the two dataframes and then select the columns you're interested in

这篇关于Spark Scala将列从一个数据框复制到另一个数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆