DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #168
The code block shown below should return a DataFrame containing only the rows from DataFrame storesDF where the value in column sqft is less than or equal to 25,000 AND the value in column customerSat
The correct answer is A. 1. filter. To filter rows by multiple conditions, PySpark's filter() (or its alias where()) is used. The combined condition must use & (bitwise AND) operator, not Python's and, and each individual condition must be wrapped in parentheses. The correct call is: storesDF.filter((col('sqft') <=
Question
The code block shown below should return a DataFrame containing only the rows from DataFrame storesDF where the value in column sqft is less than or equal to 25,000 AND the value in column customerSatisfaction is greater than or equal to 30. Choose the response that correctly fills in the numbered blanks within the code block to complete this task. Code block:
storesDF.1(2 3 4)
Options
- A
- filter
- B
- filter
- C
- filter
- D
- drop
- E
- filter
How the community answered
(33 responses)- A79% (26)
- C3% (1)
- D12% (4)
- E6% (2)
Explanation
To filter rows by multiple conditions, PySpark's filter() (or its alias where()) is used. The combined condition must use & (bitwise AND) operator, not Python's and, and each individual condition must be wrapped in parentheses. The correct call is: storesDF.filter((col('sqft') <= 25000) & (col('customerSatisfaction') >= 30)). Option D uses drop(), which removes columns from a DataFrame - not rows - making it completely wrong for this use case. The remaining options all use filter but differ in how conditions and column references are written; only option A uses the fully correct syntax with col() references and the & operator.
Topics
Community Discussion
No community discussion yet for this question.