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

Which of the following code blocks returns a DataFrame with column storeSlogan where single quotes in column storeSlogan in DataFrame storesDF have been replaced with double quotes?

A sample of DataFrame storesDF is below:

    Correct Answer: C

    To replace single quotes with double quotes in the 'storeSlogan' column of the DataFrame 'storesDF', we need to use the 'regexp_replace' function correctly. The correct syntax for 'regexp_replace' in PySpark requires specifying the column as a 'col' object and providing the pattern to search for and the string to replace it with. Therefore, the correct code block is storesDF.withColumn('storeSlogan', regexp_replace(col('storeSlogan'), "'", '"')). This code correctly identifies the 'storeSlogan' column, searches for single quotes, and replaces them with double quotes.

Discussion
Sowwy1Option: C

It's C. https://spark.apache.org/docs/latest/api/python/reference/pyspark.sql/api/pyspark.sql.functions.regexp_replace.html

sionitaOption: C

Why C and nod D ?

jtu363

needs a col object

jtu363

yes,D also works. disregard my previous comment.