QuestionQ167

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

The code block below must return a new DataFrame from DataFrame storesDF, with the numberOfManagers column set to the constant integer 1. Choose the response that correctly fills the numbered blanks in the code block to complete this task.

Code block:

storesDF._1_(_2_, _3_(_4_))  
Explanation

In PySpark, DataFrame.withColumn(colName, col) produces a new DataFrame by adding or replacing a named column, and lit(1) creates a Column expression holding the integer literal 1. Thus withColumn("numberOfManagers", lit(1)) sets that column to the integer constant for every row.

Learn more

Community Discussion

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