QuestionQ257

VerifiedUsing Spark SQL

Which code block returns a DataFrame in which the managerName column from DataFrame storesDF is split on the space character into the managerFirstName and managerLastName columns?

A sample of DataFrame storesDF is shown below:

Question Image

Explanation

PySpark's split function splits a string column around the supplied pattern and returns an array. The array elements are zero-based, so index 0 is the first name and index 1 is the last name. Chaining withColumn calls creates managerFirstName and managerLastName from those two elements.

Learn more

Community Discussion

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