如何将Spark Dataframe添加到另一个数据框的底部? [英] How to add a Spark Dataframe to the bottom of another dataframe?

查看:713
本文介绍了如何将Spark Dataframe添加到另一个数据框的底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用 withcolumn 向Dataframe添加新列。但是在scala中,如何向DataFrame添加新行呢?

I can use withcolumnto add new columns to a Dataframe. But in scala how can I add new rows to a DataFrame?

我正在尝试将数据框添加到另一个底部。因此,如何在scala中添加行或如何将DataFrame添加到另一个的底部将有所帮助。谢谢

I'm trying to add a dataframe to the bottom of another one. So either how to add rows in scala or how to add a DataFrame to the bottom of another one will help. Thanks

推荐答案

如果他们有相同的模式,只需使用

If they have the same schema, simply use union for spark 2+:

val dfUnion = df1.union(df2)

unionAll for spark 1 +:

Or unionAll for spark 1+:

val dfUnion = df1.unionAll(df2)

这篇关于如何将Spark Dataframe添加到另一个数据框的底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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