QuestionQ102

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

A data engineer is working with the DataFrame df:

Question Image

The data engineer wants the Name with the highest count to appear first at the top, followed by the Name with the next-highest count, and so on.

Which code fragment should the engineer use to sort the data in the Name and count columns?

Explanation

PySpark orderBy sorts by the specified columns, and setting ascending=False applies descending order. Ordering by count first with this setting places the highest count values first; Name serves as a secondary sort key. PySpark DataFrame.sort documentation

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!