DatabricksDatabricks
DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #4
DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK Question #4: Real Exam Question with Answer & Explanation
The correct answer is A: storesDF.withColumn("employeesPerSqft", col("numberOfEmployees") / col("sqft")). See the full explanation below for the reasoning.
Data Manipulation with Spark DataFrames
Question
Which of the following code blocks returns a new DataFrame with a new column employeesPerSqft that is the quotient of column numberOfEmployees and column sqft, both of which are from DataFrame storesDF? Note that column employeesPerSqft is not in the original DataFrame storesDF.
Options
- AstoresDF.withColumn("employeesPerSqft", col("numberOfEmployees") / col("sqft"))
- BstoresDF.withColumn("employeesPerSqft", "numberOfEmployees" / "sqft")
- CstoresDF.select("employeesPerSqft", "numberOfEmployees" / "sqft")
- DstoresDF.select("employeesPerSqft", col("numberOfEmployees") / col("sqft"))
- EstoresDF.withColumn(col("employeesPerSqft"), col("numberOfEmployees") / col("sqft"))
Topics
#DataFrame Transformations#Adding Columns#Spark SQL Functions#Column Operations
Community Discussion
No community discussion yet for this question.