Append to a DataFrame

Learn how to append to a DataFrame in Databricks.

Written by Adam Pavlacka

Last published at: September 28th, 2022

To append to a DataFrame, use the union method.

%scala

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

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