DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #79
The code block shown below should create a single-column DataFrame from Scala list years which is made up of integers. Choose the response that correctly fills in the numbered blanks within the code…
The correct answer is A. 1. spark. The code pattern __1__.__2__(__3__).__4__ maps to spark.createDataset(years).toDF("year"). Here: spark is the SparkSession, createDataset(years) converts the Scala List[Int] into a typed Dataset[Int], and toDF("year") converts it into a single-column DataFrame with the column…
Question
The code block shown below should create a single-column DataFrame from Scala list years which is made up of integers. Choose the response that correctly fills in the numbered blanks within the code block to complete this task. Code block:
1.2(3).4
Options
- A
- spark
- B
- spark
- C
- spark
- D
- spark
How the community answered
(24 responses)- A71% (17)
- B17% (4)
- C8% (2)
- D4% (1)
Explanation
The code pattern __1__.__2__(__3__).__4__ maps to spark.createDataset(years).toDF("year"). Here: spark is the SparkSession, createDataset(years) converts the Scala List[Int] into a typed Dataset[Int], and toDF("year") converts it into a single-column DataFrame with the column named "year". Option A correctly uses createDataset() for a typed Scala collection followed by toDF() to assign the column name. Using createDataFrame() directly on a plain list requires additional wrapping (e.g., as a list of tuples).
Topics
Community Discussion
No community discussion yet for this question.