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.
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.
it should be D, the first two characters should be from 0-2
upvoted 2 times
...
Log in to ExamTopics
Sign in:
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.
oussa_ama
3 months ago65bd33e
3 months, 2 weeks ago5cf7ace
5 months, 2 weeks agoJuanitoFM
9 months agoiamadoctor
9 months, 1 week agoazure_bimonster
9 months, 2 weeks agoamirshaz
10 months ago