
Answer-first summary for fast verification
Answer: storesDF.withColumn("storeSlogan", regexp_replace(col("storeSlogan"), "’", """))
The correct answer is option C. The `regexp_replace` function requires three arguments: the column (as a Column object), the pattern to replace, and the replacement string. Option C correctly uses `col("storeSlogan")` to reference the column, the single quote `'` as the pattern, and double quote `"` as the replacement. Other options have syntax errors: A uses incorrect method invocation, B and D have missing/incorrect arguments, and E uses `regexp_extract` which is for extraction, not replacement.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
Which of the following code blocks returns a DataFrame with a column storeSlogan where all single quotes in the storeSlogan column of DataFrame storesDF have been replaced with double quotes?
A sample of DataFrame storesDF is shown below:
storeId storeSlogan
0 'consequat vitae ...
1 'aliquam at pelle...
2 'non ac leo phare...
3 'eget purus vel sed"
4 'vitae phasellus ...
...
...
storeId storeSlogan
0 'consequat vitae ...
1 'aliquam at pelle...
2 'non ac leo phare...
3 'eget purus vel sed"
4 'vitae phasellus ...
...
...
A
storesDF.withColumn("storeSlogan", col("storeSlogan").regexp_replace("’" """))
B
storesDF.withColumn("storeSlogan", regexp_replace(col("storeSlogan"), "’"))
C
storesDF.withColumn("storeSlogan", regexp_replace(col("storeSlogan"), "’", """))
D
storesDF.withColumn("storeSlogan", regexp_replace("storeSlogan", "’", """))
E
storesDF.withColumn("storeSlogan", regexp_extract(col("storeSlogan"), "’", """))