I can use withcolumn
to add new columns to a Dataframe. But in scala how can I add new rows to a 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
To append row to dataframe one can use collect method also. collect() function converts dataframe to list and you can directly append data to list and again convert list to dataframe.
If they have the same schema, simply use union
for spark 2+:
val dfUnion = df1.union(df2)
Or unionAll
for spark 1+:
val dfUnion = df1.unionAll(df2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With