Question 151 · 219 in bank
The code block shown below contains an error. The code block is intended to return a new DataFrame where column managerName from DataFrame storesDF is split at the space character into column managerFirstName and column managerLastName. Identify the error. A sample of DataFrame storesDF is displayed below:

Code block: storesDF.withColumn("managerFirstName", col("managerName").split(" ").getItem(0)) .withColumn("managerLastName", col("managerName").split(" ").getItem(1))
Show answer
Answer: C
Explanation
I think it is C data = [ ("John Smith",), ("Jane Doe",), ("Mike Johnson",) ] df = spark.createDataFrame(data, ["managerName"]) df.show() df = df.withColumn("managerFirstName", split(col("managerName"), " ").getItem(0)) \ .withColumn("managerLastName", split(col("managerName"), " ").getItem(1)) df.show()
Source: Adapted from community discussion — newusername