QuestionQ115

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

Which of the following code blocks returns a new DataFrame containing a new employeesPerSqft column that is the quotient of the numberOfEmployees and sqft columns, both from the storesDF DataFrame? Note that employeesPerSqft does not exist in the original storesDF DataFrame.

Explanation

PySpark DataFrame.withColumn returns a new DataFrame after adding or replacing a column. Its first argument is the column-name string, and its second argument is a Column expression. col("numberOfEmployees") / col("sqft") creates the required quotient expression.

Learn more

Community Discussion

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