Append to a DataFrame

Learn how to append to a DataFrame in Databricks.

Written by Adam Pavlacka

Last published at: March 4th, 2022

To append to a DataFrame, use the union method.


val firstDF = spark.range(3).toDF("myCol")
val newRow = Seq(20)
val appended = firstDF.union(newRow.toDF())

firstDF = spark.range(3).toDF("myCol")
newRow = spark.createDataFrame([[20]])
appended = firstDF.union(newRow)

Was this article helpful?