QuestionQ8

VerifiedUsing Spark SQL

A developer needs to create a Python dictionary from data stored in a small Parquet table, shown below:

Question Image

The resulting Python dictionary must map region to region_id and include the three smallest region_id values.

Which code fragment meets these requirements?

Explanation

sort('region_id') sorts the DataFrame in ascending order by default, and take(3) retrieves the first three rows. Selecting region before region_id yields key-value pairs in the required region → region_id order, for IDs 0, 1, and 2.

Learn more

Community Discussion

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