DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #59
Which of the following code blocks returns a DataFrame sorted alphabetically based on column division?
The correct answer is D. storesDF.orderBy("division", ascending - true). Alphabetical sorting means ascending order. Option D - storesDF.orderBy('division', ascending=True) (note: the dash in ascending - true in the question text is a formatting artifact for =) - explicitly sorts ascending by 'division'. Options B and C use desc(), which sorts…
Question
Which of the following code blocks returns a DataFrame sorted alphabetically based on column division?
Options
- AstoresDF.sort("division")
- BstoresDF.orderBy(desc("division"))
- CstoresDF.orderBy(col("division").desc())
- DstoresDF.orderBy("division", ascending - true)
- EstoresDF.sort(desc("division"))
How the community answered
(14 responses)- B7% (1)
- D93% (13)
Explanation
Alphabetical sorting means ascending order. Option D - storesDF.orderBy('division', ascending=True) (note: the dash in ascending - true in the question text is a formatting artifact for =) - explicitly sorts ascending by 'division'. Options B and C use desc(), which sorts descending (reverse alphabetical). Options E also uses desc(). Option A - storesDF.sort('division') - does sort ascending by default and would technically work, but option D is preferred as it explicitly declares the sort direction with ascending=True, making the intent unambiguous and matching the canonical orderBy method.
Topics
Community Discussion
No community discussion yet for this question.