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()
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.
bp_a_user
2 weeks, 4 days agooussa_ama
5 months, 2 weeks ago65bd33e
5 months, 4 weeks ago[Removed]
7 months, 4 weeks agoJuanitoFM
11 months, 1 week agoiamadoctor
11 months, 3 weeks agoazure_bimonster
12 months agoamirshaz
1 year ago