nerdexam
Databricks

DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #117

Which of the following code blocks returns a new DataFrame that is the result of a position-wise union between DataFrame storesDF and DataFrame acquiredStoresDF?

The correct answer is E. storesDF.union(acquiredStoresDF). In PySpark, DataFrame.union(other) performs a position-wise union - rows are combined by column position, not by column name. storesDF.union(acquiredStoresDF) is the correct syntax. Choice A uses unionByName(), which aligns columns by name rather than by position - this is the…

Transforming Data with Spark DataFrames

Question

Which of the following code blocks returns a new DataFrame that is the result of a position-wise union between DataFrame storesDF and DataFrame acquiredStoresDF?

Options

  • AstoresDF.unionByName(acquiredStoresDF)
  • BunionAll(storesDF, acquiredStoresDF)
  • Cunion(storesDF, acquiredStoresDF)
  • Dconcat(storesDF, acquiredStoresDF)
  • EstoresDF.union(acquiredStoresDF)

How the community answered

(59 responses)
  • B
    3% (2)
  • C
    5% (3)
  • D
    2% (1)
  • E
    90% (53)

Explanation

In PySpark, DataFrame.union(other) performs a position-wise union - rows are combined by column position, not by column name. storesDF.union(acquiredStoresDF) is the correct syntax. Choice A uses unionByName(), which aligns columns by name rather than by position - this is the opposite of what the question asks. Choices B, C, and D attempt to use standalone functions (unionAll(), union(), concat()) that are not valid in PySpark's DataFrame API - there is no module-level union() or concat() for DataFrames.

Topics

#Spark DataFrame#Data Transformation#Union Operation#DataFrame API

Community Discussion

No community discussion yet for this question.

Full DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK Practice