Exam Certified Associate Developer for Apache Spark All QuestionsBrowse all questions from this exam
Question 151

Which of the following code blocks returns a new DataFrame with column storeReview where the pattern "End" has been removed from the end of column storeReview in DataFrame storesDF?

A sample DataFrame storesDF is below:

    Correct Answer: B

    To remove the pattern ' End' from the end of the column 'storeReview' in the DataFrame 'storesDF', the correct code block should use the 'regexp_replace' function along with the 'col' function correctly. The correct implementation is 'storesDF.withColumn("storeReview", regexp_replace(col("storeReview"), " End$", ""))'. This method ensures that the 'regexp_replace' function operates on the column 'storeReview,' replacing the pattern ' End' that appears at the end of the string. Therefore, option B is the correct choice.

Discussion
saryuOption: B

B also works right?

SaiPavan10Option: B

B is the right choice

jtu363Option: B

B & D work

azure_bimonsterOption: B

B is right one it seems, col should be used