DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #17
Which of the following code blocks fails to return a DataFrame reverse sorted alphabetically based on column division?
The correct answer is C. storesDF.orderBy(col("division").asc()). col("division").asc() explicitly sorts in ascending (A → Z) alphabetical order, which is the opposite of reverse (descending) alphabetical order. Therefore, option C fails to meet the requirement. The other options correctly achieve descending sort: B uses ascending=[0] (0 is…
Question
Which of the following code blocks fails to return a DataFrame reverse sorted alphabetically based on column division?
Options
- AstoresDF.orderBy("division", ascending - False)
- BstoresDF.orderBy(["division"], ascending = [0])
- CstoresDF.orderBy(col("division").asc())
- DstoresDF.sort("division", ascending - False)
- EstoresDF.sort(desc("division"))
How the community answered
(26 responses)- A8% (2)
- C88% (23)
- E4% (1)
Explanation
col("division").asc() explicitly sorts in ascending (A → Z) alphabetical order, which is the opposite of reverse (descending) alphabetical order. Therefore, option C fails to meet the requirement. The other options correctly achieve descending sort: B uses ascending=[0] (0 is falsy, equivalent to False); E uses the desc() function which sorts descending. Options A and D contain a Python syntax quirk (ascending - False uses subtraction instead of =), but the exam identifies C as the clear failure because .asc() unambiguously forces ascending order.
Topics
Community Discussion
No community discussion yet for this question.