
Answer-first summary for fast verification
Answer: storesDF.withColumn("storeId, col("storeId").cast(StringType()))
The correct code block uses `col("storeId").cast(StringType())` to cast the column to StringType. Option B correctly applies this method. Other options have syntax errors: missing quotes, incorrect use of `cast`, or misuse of `as`. Despite apparent quote typos in the options, B's approach is valid when quotes are properly closed.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
Which of the following code blocks returns a new DataFrame from DataFrame storesDF where column storeId has a string data type?
A
storesDF.withColumn("storeId, cast(col("storeId"), StringType()))
B
storesDF.withColumn("storeId, col("storeId").cast(StringType()))
C
storesDF.withColumn("storeId, cast(storeId).as(StringType)
D
storesDF.withColumn("storeId, col(storeId).cast(StringType)
E
storesDF.withColumn("storeId, cast("storeId").as(StringType()))
No comments yet.