
Answer-first summary for fast verification
Answer: storesDF.orderBy(["division"], ascending = [0]), storesDF.orderBy(col("division").asc())
To reverse sort a DataFrame alphabetically based on the 'division' column, the correct method involves specifying the column and setting the ascending parameter to False or using the desc function. Analyzing the options: - **A**: Contains a syntax error due to the use of a hyphen (–) instead of an equals sign (=) in 'ascending – False'. This will fail to execute. - **B**: Attempts to use a list for the ascending parameter with an integer (0) instead of a boolean (False), which is incorrect syntax for PySpark and will fail. - **C**: Incorrectly uses .asc() which sorts in ascending order, opposite of what is required. - **D**: Similar to A, contains a syntax error with 'ascending – False'. - **E**: Correctly uses the desc function to sort the 'division' column in descending order. Given the options, A, B, C, and D fail to correctly reverse sort the DataFrame, but since the question specifies to select two correct answers when five options are provided, the most accurate choices highlighting different types of errors are B (incorrect parameter type) and C (wrong sort direction).
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
Which of the following code blocks fails to return a DataFrame sorted in reverse alphabetical order based on the column 'division'?
A
storesDF.orderBy("division", ascending – False)
B
storesDF.orderBy(["division"], ascending = [0])
C
storesDF.orderBy(col("division").asc())
D
storesDF.sort("division", ascending – False)
E
storesDF.sort(desc("division"))