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…
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)- B3% (2)
- C5% (3)
- D2% (1)
- E90% (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
Community Discussion
No community discussion yet for this question.