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

Certified Associate Developer for Apache Spark 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:

Show Answer
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

2 comments
Sign in to comment
sionitaOption: C
Mar 29, 2024

Why C and nod D ?

jtu363
May 23, 2024

needs a col object

jtu363
May 23, 2024

yes,D also works. disregard my previous comment.

Sowwy1Option: C
Apr 10, 2024

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