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 >…
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)- A7% (4)
- B12% (7)
- C2% (1)
- D78% (47)
- E2% (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
Community Discussion
No community discussion yet for this question.