exam questions

Exam Certified Associate Developer for Apache Spark All Questions

View all questions & answers for the Certified Associate Developer for Apache Spark exam

Exam Certified Associate Developer for Apache Spark topic 1 question 71 discussion

The code block shown below should return a new DataFrame where single quotes in column storeSlogan have been replaced with double quotes. Choose the response that correctly fills in the numbered blanks within the code block to complete this task.

A sample of DataFrame storesDF is below:



Code block:

storesDF.__1__(__2__, __3__(__4__, __5__, __6__))

  • A. 1. withColumn
    2. "storeSlogan"
    3. regexp_extract
    4. col("storeSlogan")
    5. "\""
    6. "'"
  • B. 1. newColumn
    2. storeSlogan
    3. regexp_extract
    4. col(storeSlogan)
    5. "\""
    6. "'"
  • C. 1. withColumn
    2. "storeSlogan"
    3. regexp_replace
    4. col("storeSlogan")
    5. "\""
    6. "'"
  • D. 1. withColumn
    2. "storeSlogan"
    3. regexp_replace
    4. col("storeSlogan")
    5. "'"
    6. "\""
  • E. 1. withColumn
    2. "storeSlogan"
    3. regexp_extract
    4. col("storeSlogan")
    5. "'"
    6. "\""
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Selected Answer: D
In Python, the expression '"' (double quote inside single quotes) or \" (escaped double quote) both represent a double quote ("). In the correct answer D, the replacement part is written as: regexp_replace(col("storeSlogan"), "'", "\"") The first argument ("storeSlogan") refers to the column to be modified. The second argument ("'") specifies the single quote character to be replaced. The third argument ("\"" or '"') represents the double quote character that will replace the single quote. Since Python uses backslashes (\) to escape special characters, \" ensures that the double quote is correctly interpreted as part of the replacement string. So, in short: ✅ ' " ' and ' \" ' are equivalent in this case, both representing a double quote.
upvoted 1 times
...
azure_bimonster
8 months, 3 weeks ago
Selected Answer: D
To me it would like this: storesDF.withColumn("storeSlogan", regexp_replace(col("storeSlogan"), " ' ", "\""))
upvoted 1 times
...
cookiemonster42
1 year, 3 months ago
Selected Answer: D
D is correct, we need a replacement function with first argument "'"
upvoted 2 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago