
Answer-first summary for fast verification
Answer: storesDF.withColumnRenamed("division", "state") .withColumnRenamed("managerName", "managerFullName")
The question requires renaming columns 'division' to 'state' and 'managerName' to 'managerFullName' in the DataFrame. The correct method is `withColumnRenamed`, which takes the existing column name and the new name. Option A chains two `withColumnRenamed` calls to achieve both renames. Options B and C use `withColumn`, which creates new columns instead of renaming existing ones. Option D uses invalid syntax for `withColumnRenamed`, which does not accept sequences. Option E incorrectly reverses the renaming order.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
Which of the following code blocks returns a new DataFrame where:
division from DataFrame storesDF is replaced and renamed to statemanagerName from DataFrame storesDF is replaced and renamed to managerFullName?A
storesDF.withColumnRenamed("division", "state") .withColumnRenamed("managerName", "managerFullName")
B
storesDF.withColumn("state", "division") .withColumn("managerFullName", "managerName")
C
storesDF.withColumn("state", col("division")) .withColumn("managerFullName", col("managerName"))
D
storesDF.withColumnRenamed(Seq("division", "state"), Seq("managerName", "managerFullName"))
E
storesDF.withColumnRenamed("state", "division") .withColumnRenamed("managerFullName", "managerName")
No comments yet.