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?
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
Cammy
22 days agoLemuel
27 days agoRebecka
1 month agoAmber
1 month agoFlorinda
1 month agoCordie
2 months agoCordelia
2 months agoCelestina
2 months agoAngelo
2 months agoKeneth
2 months agoJanna
2 months agoErick
3 months ago