DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #25
The code block shown below should create a single-column DataFrame from Python list years which is made up of integers. Choose the response that correctly fills in the numbered blanks within the…
The correct answer is E. 1. spark. To create a single-column DataFrame from a Python list of integers, you use spark.createDataFrame(). For a flat list (not a list of tuples), you must pass the schema explicitly so Spark knows the column name and type. The correct form is spark.createDataFrame(years…
Question
The code block shown below should create a single-column DataFrame from Python 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
- DataFrame
- C
- spark
- D
- spark
- E
- spark
How the community answered
(34 responses)- B3% (1)
- D3% (1)
- E94% (32)
Explanation
To create a single-column DataFrame from a Python list of integers, you use spark.createDataFrame(). For a flat list (not a list of tuples), you must pass the schema explicitly so Spark knows the column name and type. The correct form is spark.createDataFrame(years, IntegerType()) for a single column of integers, or with a column name schema. Option E correctly uses spark as the entry point and createDataFrame with the list and an appropriate schema.
Topics
Community Discussion
No community discussion yet for this question.