QuestionQ69

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

The code block below has an error. It is intended to create a single-column DataFrame from the Python list years, which consists of integers. Identify the error.

Code block:

spark.createDataFrame(years, IntegerType)  
Explanation

createDataFrame requires the schema argument to be a PySpark DataType instance when specifying a scalar type. IntegerType() creates that instance; IntegerType is only the class reference. With a non-StructType schema such as IntegerType(), Spark creates a single field named value and wraps each integer as one row.

Learn more

Community Discussion

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