nerdexam
Databricks

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') <=

Perform DataFrame Transformations

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
    1. filter
  • B
    1. filter
  • C
    1. filter
  • D
    1. drop
  • E
    1. filter

How the community answered

(33 responses)
  • A
    79% (26)
  • C
    3% (1)
  • D
    12% (4)
  • E
    6% (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

#Spark DataFrames#DataFrame Filtering#Conditional Logic#Column Operations

Community Discussion

No community discussion yet for this question.

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