Databricks Certified Associate Developer For Apache Spark 30 · Free Practice Question Easy

Question 7

Which of the following code blocks concatenates two DataFrames df1 and df2 ?

  • A

    df1.addAll(df2)

  • B

    df1.append(df2)

  • C

    df1.add(df2)

  • D

    df1.appendAll(df2)

  • E

    df1.union(df2)

Reveal correct answer

Correct answer: E

Explanation

DataFrames are immutable. This means users cannot append to DataFrames because that would be changing it. To append to a DataFrame, you must union the original DataFrame along with the new DataFrame.


To concatenate two DataFrames in Apache Spark, you can use the union() method of the DataFrame class. This method combines the rows of two DataFrames into a single DataFrame.

Here is an example of how to use union() in Scala:

This will produce a new DataFrame df3 that includes all the rows from both df1 and df2:

In Python, you can use the following code to achieve the same result:

Therefore, the code block that concatenates two DataFrames df1 and df2 is:

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need