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 (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
bp_a_user
2 weeks, 4 days ago
Selected Answer: E
Assuming here substring: The position is not zero based, but 1 based index. So this makes the job: df1.withColumn("splitcol",F.substring(F.col("name"),1,2)).display()
upvoted 1 times
...
oussa_ama
5 months, 2 weeks ago
Selected Answer: E
df = spark.createDataFrame([('abcd',)], ['s',]) df.select(substring(df.s, 1, 2).alias('s')).collect()
upvoted 1 times
...
65bd33e
5 months, 4 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
...
[Removed]
7 months, 4 weeks ago
Selected Answer: D
D is right
upvoted 2 times
...
JuanitoFM
11 months, 1 week ago
Selected Answer: D
it should be D, the first two characters should be from 0-2
upvoted 3 times
...
iamadoctor
11 months, 3 weeks ago
Selected Answer: E
E is right
upvoted 2 times
...
azure_bimonster
12 months 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
1 year 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 ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago