Certified Associate Developer for Apache Spark Exam QuestionsBrowse all questions from this exam

Certified Associate Developer for Apache Spark Exam - Question 28


Which of the following code blocks returns a new DataFrame where column division from DataFrame storesDF has been replaced and renamed to column state and column managerName from DataFrame storesDF has been replaced and renamed to column managerFullName?

Show Answer
Correct Answer: E

To return a new DataFrame where the column 'division' from DataFrame 'storesDF' has been replaced and renamed to 'state' and the column 'managerName' from DataFrame 'storesDF' has been replaced and renamed to 'managerFullName', the correct method to use is 'withColumnRenamed'. The 'withColumnRenamed' function is designed specifically for renaming existing columns in a DataFrame. Therefore, using 'withColumnRenamed' to change 'division' to 'state' and 'managerName' to 'managerFullName' achieves the desired result.

Discussion

6 comments
Sign in to comment
4be8126Option: E
Apr 26, 2023

Option E is the correct answer. The withColumnRenamed function renames an existing column, whereas withColumn creates a new column. To replace the "division" column with a new column "state" and rename the "managerName" column to "managerFullName", we need to use withColumnRenamed. So option E is correct, where we first rename "division" to "state" and then rename "managerName" to "managerFullName".

NickWerbungOption: E
Jul 1, 2023

DataFrame.withColumnRenamed(existing, new)

MohitsainOption: D
Jun 22, 2023

this is the right answer.

zozoshankyOption: D
Jul 30, 2023

D is right

evertonllinsOption: B
Aug 26, 2023

If we take in consideration this part of the text .-> "has been REPLACED and renamed to..." it means that the columnis not only renames but replaved with the contents of the other clumn. In this case the righr answer is B. Do you guys thin this insterpretation is correct? Thanks for the feedback.

azure_bimonsterOption: E
Feb 8, 2024

E is the right answer for this question