Certified Associate Developer for Apache Spark Exam QuestionsBrowse all questions from this exam

Certified Associate Developer for Apache Spark Exam - Question 19


The code block shown below contains an error. The code block is intended to return a DataFrame containing all columns from DataFrame storesDF except for column sqft and column customerSatisfaction. Identify the error.

Code block:

storesDF.drop(sqft, customerSatisfaction)

Show Answer
Correct Answer: D

The code block is intended to drop two columns from the DataFrame storesDF. The drop function in a DataFrame expects column names to be provided as strings. Therefore, the column names should be quoted like "sqft" and "customerSatisfaction". The corrected code block should be: storesDF.drop("sqft", "customerSatisfaction").

Discussion

5 comments
Sign in to comment
4be8126Option: D
Apr 26, 2023

The error in the code block is that the column names sqft and customerSatisfaction should be quoted, like "sqft" and "customerSatisfaction", since they are strings. The correct code block should be: storesDF.drop("sqft", "customerSatisfaction") Option D correctly identifies this error.

ZSun
Jun 7, 2023

The correct one is B: storesDF.drop("sqft").drop("customerSatisfaction") For D, it should be list of column name: storesDF.drop(["sqft", "customerSatisfaction"])

ZSun
Jun 7, 2023

The correct one is D, but my explanation is correct

TmDataOption: D
Jun 17, 2023

When using the drop() operation in Spark DataFrame, the column names should be specified as strings and enclosed in quotes. In the given code block, the column names "sqft" and "customerSatisfaction" are not quoted, which results in a syntax error.

zozoshankyOption: D
Jul 30, 2023

D is correct, df.drop('id','firstname').show() tested code

azurearchOption: A
Mar 6, 2024

https://spark.apache.org/docs/latest/api/python/reference/pyspark.sql/api/pyspark.sql.DataFrame.drop.html option A is correct, drop expects only one argument, if its more than one, you would have to use as listofcols=['col1','col2'] and drop(*listofcols)

azurearchOption: D
Mar 6, 2024

sorry, Option D is correct