
Answer-first summary for fast verification
Answer: storesDF.sort("division")
To sort a DataFrame alphabetically based on a column in ascending order, the correct method is to use `sort` or `orderBy` without specifying a descending order. Option A correctly uses `sort("division")`, which sorts the DataFrame in ascending order by default. Options B, C, and E incorrectly sort the DataFrame in descending order due to the use of `desc`. Option D contains a syntax error with `ascending - true` instead of the correct `ascending=True`. Therefore, the only correct option is A.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
Which of the following code blocks returns a DataFrame sorted in alphabetical order by the column division?
A
storesDF.sort("division")
B
storesDF.orderBy(desc("division"))
C
storesDF.orderBy(col("division").desc())
D
storesDF.orderBy("division", ascending - true)
E
storesDF.sort(desc("division"))
No comments yet.