Certified Associate Developer for Apache Spark Exam QuestionsBrowse all questions from this exam

Certified Associate Developer for Apache Spark Exam - Question 134


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

Show Answer
Correct Answer: BE

To extract the first two characters of a column in a DataFrame, the correct method is to use the substr function. The starting index for substr function in PySpark is 1-based. Therefore, to get the first two characters, the start index should be 1 and the length should be 2. So, 'storesDF.withColumn("division", susbtr(col("division"), 1, 2))' is correct because it correctly specifies the start index as 1 and the length as 2.

Discussion

5 comments
Sign in to comment
amirshazOption: D
Jan 24, 2024

it should be D, the first two characters should be from 0-2

iamadoctorOption: E
Feb 20, 2024

E is right

JuanitoFMOption: D
Feb 29, 2024

it should be D, the first two characters should be from 0-2

azure_bimonsterOption: D
Feb 9, 2024

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.

5cf7aceOption: D
Jun 12, 2024

D is right