DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #49
The code block shown below should return a new DataFrame from DataFrame storesDF where column storeId is of the type string. Choose the response that correctly fills in the numbered blanks within…
The correct answer is A. 1. withColumn. The correct completed code is: storesDF.withColumn('storeId', col('storeId').cast(StringType())). Blank 1 is withColumn (replaces or adds a column), blank 2 is col (creates a Column reference from the existing column), blank 3 is cast (converts the column to a new data type)…
Question
The code block shown below should return a new DataFrame from DataFrame storesDF where column storeId is of the type string. Choose the response that correctly fills in the numbered blanks within the code block to complete this task. Code block:
storesDF.1("storeId", 2("storeId").3(4)
Options
- A
- withColumn
- B
- withColumn
- C
- newColumn
- D
- withColumn
- E
- withColumn
How the community answered
(38 responses)- A89% (34)
- B3% (1)
- D5% (2)
- E3% (1)
Explanation
The correct completed code is: storesDF.withColumn('storeId', col('storeId').cast(StringType())). Blank 1 is withColumn (replaces or adds a column), blank 2 is col (creates a Column reference from the existing column), blank 3 is cast (converts the column to a new data type), and blank 4 is StringType() (the Spark SQL type representing a string). withColumn overwrites the storeId column with a cast version of itself. The cast() method accepts either a DataType object like StringType() or a string alias like 'string'.
Topics
Community Discussion
No community discussion yet for this question.