Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
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 135 discussion

Which of the following code blocks returns a new DataFrame where column division is the first two characters of column division in DataFrame storesDF?

  • A. storesDF.withColumn(“division”, substr(col(“division”), 0, 2))
  • B. storesDF.withColumn(“division”, susbtr(col(“division”), 1, 2))
  • C. storesDF,withColumn(“division”, col(“division”).substr(0, 3))
  • D. storesDF.withColumn(“division”, col(“division”).substr(0, 2))
  • E. storesDF.withColumn(“division”, col(“division”).substr(l, 2))
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
oussa_ama
3 months ago
Selected Answer: E
df = spark.createDataFrame([('abcd',)], ['s',]) df.select(substring(df.s, 1, 2).alias('s')).collect()
upvoted 1 times
...
65bd33e
3 months, 2 weeks ago
Selected Answer: B
The correct code block that returns a new DataFrame where the column division is the first two characters of the division column in DataFrame storesDF is: B. storesDF.withColumn(“division”, substr(col(“division”), 1, 2)) Explanation: substr(col(“division”), 1, 2) extracts the substring starting from the 1st character (index 1) and takes the next 2 characters. Spark's substr function is 1-indexed, meaning it starts counting from 1, not 0.
upvoted 1 times
...
5cf7ace
5 months, 2 weeks ago
Selected Answer: D
D is right
upvoted 2 times
...
JuanitoFM
9 months ago
Selected Answer: D
it should be D, the first two characters should be from 0-2
upvoted 3 times
...
iamadoctor
9 months, 1 week ago
Selected Answer: E
E is right
upvoted 2 times
...
azure_bimonster
9 months, 2 weeks ago
Selected Answer: D
D would be correct as it asks first two characters. - substr(startIndex: Int, length: Int): This function takes two arguments: -> startIndex: The starting index of the substring to extract. Indexing starts from 0. -> length: The length of the substring to extract.
upvoted 2 times
...
amirshaz
10 months ago
it should be D, the first two characters should be from 0-2
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 ...