QuestionQ245

VerifiedData Processing & Transformations

A data engineer needs to clean a bronze table by removing any rows in which either the customer_email column or the customer_phone column contains a null value. This cleaning step must be accomplished in a single operation using just one method call.

Which PySpark approach allows filtering for nulls across multiple columns in a single call?

Explanation

The dropna() method on a PySpark DataFrame accepts a subset parameter listing the columns to check, and by default uses how='any', meaning it drops a row if any of the specified columns contain a null. Passing df.dropna(subset=['customer_email', 'customer_phone']) removes any row where either column is null, satisfying the requirement in a single method call. This is the purpose-built, idiomatic API for multi-column null filtering, as documented in the PySpark and Databricks API references for DataFrame.dropna.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!