DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #108
The code block shown below should return a new DataFrame where column division from DataFrame storesDF has been renamed to column state and column managerName from DataFrame storesDF has been…
The correct answer is A. 1. withColumnRenamed. To rename columns in a Spark DataFrame, you chain calls to withColumnRenamed(existingName, newName). The correct method name is withColumnRenamed - all lowercase except the C, R, and N (camelCase). Answer A uses the correctly spelled and correctly cased withColumnRenamed…
Question
The code block shown below should return a new DataFrame where column division from DataFrame storesDF has been renamed to column state and column managerName from DataFrame storesDF has been renamed to column managerFullName. Choose the response that correctly fills in the numbered blanks within the code block to complete this task. Code block:
storesDF. 1(2, 2).4(5, 6)
Options
- A
- withColumnRenamed
- B1.withColumnRenamed
- C
- WithColumnRenamed
- D
- withColumn
- E
- withColumn
How the community answered
(26 responses)- A88% (23)
- B8% (2)
- C4% (1)
Explanation
To rename columns in a Spark DataFrame, you chain calls to withColumnRenamed(existingName, newName). The correct method name is withColumnRenamed - all lowercase except the C, R, and N (camelCase). Answer A uses the correctly spelled and correctly cased withColumnRenamed. Answer B is missing the space after '1.', Answer C uses 'WithColumnRenamed' with an uppercase W (invalid), and answers D and E use withColumn which creates or replaces a column rather than renaming it. The full correct chain would be: storesDF.withColumnRenamed('division', 'state').withColumnRenamed('managerName', 'managerFullName').
Topics
Community Discussion
No community discussion yet for this question.