
Ultimate access to all questions.
The following code block contains an error. It is intended to split the managerName column from DataFrame storesDF at the space character into two new columns (managerFirstName and managerLastName). Identify the error.
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
Code block:
storesDF.withColumn("managerFirstName", col("managerName").split(" ").getItem(0))
.withColumn("managerLastName", col("managerName").split(" ").getItem(1))
storesDF.withColumn("managerFirstName", col("managerName").split(" ").getItem(0))
.withColumn("managerLastName", col("managerName").split(" ").getItem(1))
A
The index values of 0 and 1 are not correct – they should be 1 and 2, respectively.
B
The index values of 0 and 1 should be provided as second arguments to the split() operation rather than indexing the result.
C
The split() operation comes from the imported functions object. It accepts a string column name and split character as arguments. It is not a method of a Column object.
D
The split() operation comes from the imported functions object. It accepts a Column object and split character as arguments. It is not a method of a Column object.
E
The withColumn operation cannot be called twice in a row.