QuestionQ136

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

The code block below must return a new DataFrame in which the division column from DataFrame storesDF is renamed to state, and the managerName column from DataFrame storesDF is renamed to managerFullName. Choose the response that correctly fills the numbered blanks in the code block to complete this task.

Code block:

storesDF. __1__(__2__, __2__).__4__(__5__, __6__)

Explanation

The DataFrame API method for renaming an existing column is withColumnRenamed(existing, new), which accepts the current column name as its first string argument and the desired new name as its second string argument; withColumn, by contrast, adds or replaces a column based on a column expression and is not the correct choice for a simple rename. Chaining two withColumnRenamed calls with ("division", "state") and ("managerName", "managerFullName") in that argument order correctly renames both columns as required.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!