scala 如何将 Spark 数据帧添加到另一个数据帧的底部?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33550983/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 07:46:37  来源:igfitidea点击:

How to add a Spark Dataframe to the bottom of another dataframe?

scalaapache-sparkdataframe

提问by Gavin Niu

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

我可以用来withcolumn向数据框添加新列。但是在 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

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

回答by Jean Logeart

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

如果它们具有相同的架构,只需union用于 spark 2+:

val dfUnion = df1.union(df2)

Or unionAllfor spark 1+:

或者unionAll对于火花 1+:

val dfUnion = df1.unionAll(df2)