Ultimate access to all questions.
Which of the following code blocks returns a DataFrame sorted in alphabetical order by the column division
?
Explanation:
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.