QuestionQ21

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

A data scientist at an e-commerce company is working with user data obtained from its subscriber database and stored in a DataFrame named df_user. Before processing the data further, the data scientist wants to create another DataFrame, df_user_non_pii, containing only the non-PII columns. The PII columns in df_user are first_name, last_name, email, and birthdate.

Which code snippet can be used to meet this requirement?

Explanation

PySpark DataFrame.drop(*cols) accepts multiple column names and returns a new DataFrame without those specified columns. Dropping first_name, last_name, email, and birthdate removes the PII fields, leaving the non-PII columns.

Learn more

Community Discussion

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