Question 91 · 219 in bank
Which of the following code blocks returns a DataFrame where column managerName from DataFrame storesDF is split at the space character into column managerFirstName and column managerLastName? A sample of DataFrame storesDF is displayed below:

Show answer
Answer: A
Explanation
Right answer is A as the array returned by the split function is 0-based not 1-based. You can try yourself with the following code: df = spark.createDataFrame([('John Doe',)], ['Person',]) df2 = df \ .withColumn('first_name', split(col('Person'), ' ')[0]) \ .withColumn('last_name', split(col('Person'), ' ')[1]) df2.show()
Source: Adapted from community discussion — max_manfred
