Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Databricks Certified Associate Developer for Apache Spark 3.5 Exam - Topic 3 Question 17 Discussion

Posted by Merrilee on Jun 19, 2026 at 04:50 AM

A DataFrame df has columns name, age, and salary. The developer needs to sort the DataFrame by age in ascending order and salary in descending order.

Which code snippet meets the requirement of the developer?

Suggested Answer: D

To sort a PySpark DataFrame by multiple columns with mixed sort directions, the correct usage is:

python

CopyEdit

df.orderBy('age', 'salary', ascending=[True, False])

age will be sorted in ascending order

salary will be sorted in descending order

The orderBy() and sort() methods in PySpark accept a list of booleans to specify the sort direction for each column.

Documentation Reference: PySpark API - DataFrame.orderBy


Get Premium Databricks Certified Associate Developer for Apache Spark 3.5 Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
12 comments · newest first
CA
Cammy 2 months ago
B doesn't sort salary correctly. D is the right choice!
LE
Lemuel 2 months ago
I feel confused. Why not B? It seems simpler.
RE
Rebecka 3 months ago
I think option D is correct. It sorts age ascending and salary descending.
AM
Amber 3 months ago
Not sure about D, seems too simple for complex sorting.
FL
Florinda 3 months ago
Wait, can you really sort like that in one line?
CO
Cordie 3 months ago
D makes total sense, I agree with that choice!
CO
Cordelia 3 months ago
I think B is wrong, it sorts both in ascending order.
CE
Celestina 3 months ago
Option D is the correct one! Sorting by age asc and salary desc.
AN
Angelo 4 months ago
I feel like option A is close, but I’m pretty sure we need to sort salary in descending order, which it doesn’t do.
KE
Keneth 4 months ago
I practiced something similar last week, but I can't recall if we used "ascending" as a list or just as a single argument.
JA
Janna 4 months ago
I think option D looks familiar; it seems like the right way to specify different sort orders for each column.
ER
Erick 4 months ago
I remember sorting DataFrames, but I’m not sure if the orderBy function uses ascending as a parameter.
0/2000 characters

Save Cancel