QuestionQ208

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

A data engineer is working with the following DataFrame:

Question Image

Which code fragment should the engineer use to extract the distinct values from the Name column into an alphabetically sorted list?

Explanation

select("Name").distinct() retains one row for each unique name, and orderBy(df["Name"]) sorts those rows by the name column in ascending order by default. This yields the unique names in alphabetical order.

Learn more

Community Discussion

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