nerdexam
Databricks

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…

Working with Spark DataFrames

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
    1. spark
  • B
    1. DataFrame
  • C
    1. spark
  • D
    1. spark
  • E
    1. spark

How the community answered

(34 responses)
  • B
    3% (1)
  • D
    3% (1)
  • E
    94% (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

#PySpark#DataFrame creation#SparkSession#Schema definition

Community Discussion

No community discussion yet for this question.

Full DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK Practice