
Explanation:
The correct answer is option A because it correctly uses the split function on the managerName column to split the names at the space character and then accesses the first and second elements of the resulting array with indices [0] and [1] to create the managerFirstName and managerLastName columns, respectively. The other options either incorrectly apply the split function, use wrong indices, or have syntax errors.
Ultimate access to all questions.
Which of the following code blocks correctly splits the managerName column from DataFrame storesDF at the space character into two new columns named managerFirstName and managerLastName?
A sample of DataFrame storesDF is shown below:
storeId open openDate managerName
0 true 1100746394 Vulputate Curabitur
1 true 944572255 Tempor Augue
2 false 925495628 Aliquam Et
3 true 1397353092 Faucibus Orci
4 true 986505057 Sed Fermentum
storeId open openDate managerName
0 true 1100746394 Vulputate Curabitur
1 true 944572255 Tempor Augue
2 false 925495628 Aliquam Et
3 true 1397353092 Faucibus Orci
4 true 986505057 Sed Fermentum
A
(storesDF.withColumn("managerFirstName", split(col("managerName"), " ")[0]) .withColumn("managerLastName", split(col("managerName"), " ")[1]))
B
(storesDF.withColumn("managerFirstName", col("managerName"). split(" ")[1]) .withColumn("managerLastName", col("managerName").split(" ")[2]))
C
(storesDF.withColumn("managerFirstName", split(col("managerName"), " ")[1]) .withColumn("managerLastName", split(col("managerName"), " ")[2]))
D
(storesDF.withColumn("managerFirstName", col("managerName").split(" ")[0]) .withColumn("managerLastName", col("managerName").split(" ")[1]))
E
(storesDF.withColumn("managerFirstName", split("managerName"), " ")[0]) .withColumn("managerLastName", split("managerName"), " ")[1]))
No comments yet.