Exam Certified Associate Developer for Apache Spark All QuestionsBrowse all questions from this 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?

    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
4be8126Option: E

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

DataFrame.withColumnRenamed(existing, new)

azure_bimonsterOption: E

E is the right answer for this question

evertonllinsOption: B

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.

zozoshankyOption: D

D is right

MohitsainOption: D

this is the right answer.