nerdexam
Databricks

DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #47

Which of the following code blocks returns a DataFrame containing only the rows from DataFrame storesDF where the value in column sqft is less than or equal to 25,000?

The correct answer is D. storesDF.filter(col("sqft") <= 25000). storesDF.filter(col('sqft') <= 25000) is the correct syntax. col('sqft') creates a Column object from the string column name, and the <= operator produces a boolean Column expression suitable for filtering. Option A uses > (wrong direction) and unquoted sqft. Option B uses >…

Performing Data Transformations with Spark DataFrames

Question

Which of the following code blocks returns a DataFrame containing only the rows from DataFrame storesDF where the value in column sqft is less than or equal to 25,000?

Options

  • AstoresDF.where(storesDF[sqft] > 25000)
  • BstoresDF.filter(sqft > 25000)
  • CstoresDF.filter("sqft" <= 25000)
  • DstoresDF.filter(col("sqft") <= 25000)
  • EstoresDF.where(sqft > 25000)

How the community answered

(60 responses)
  • A
    7% (4)
  • B
    12% (7)
  • C
    2% (1)
  • D
    78% (47)
  • E
    2% (1)

Explanation

storesDF.filter(col('sqft') <= 25000) is the correct syntax. col('sqft') creates a Column object from the string column name, and the <= operator produces a boolean Column expression suitable for filtering. Option A uses > (wrong direction) and unquoted sqft. Option B uses > (wrong direction) and omits col(). Option C attempts to apply <= directly to a plain string 'sqft', which is not valid. Option E omits col() and uses >, so sqft would be treated as an undefined Python variable and the comparison is inverted.

Topics

#Spark DataFrames#Filtering Data#Column Expressions#DataFrame Transformations

Community Discussion

No community discussion yet for this question.

Full DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK Practice