DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK-3-0 practice question 9 of 25

Which of the following code blocks returns a single-column DataFrame showing the number of words in column supplier of DataFrame itemsDf? Sample of…

Full set: 180 questions
Which of the following code blocks returns a single-column DataFrame showing the number of words in column supplier of DataFrame itemsDf? Sample of DataFrame itemsDf: 1. +------+-----------------------------+-------------------+ 2. |itemId|attributes |supplier | 3. +------+-----------------------------+-------------------+ 4. |1 |[blue, winter, cozy] |Sports Company Inc.| 5. |2 |[red, summer, fresh, cooling]|YetiX | 6. |3 |[green, summer, travel] |Sports Company Inc.| 7. +------+-----------------------------+-------------------+
Answer options
A: itemsDf.split("supplier", " ").count()
B: itemsDf.split("supplier", " ").size()
C: itemsDf.select(word_count("supplier"))
D: spark.select(size(split(col(supplier), " ")))
E: itemsDf.select(size(split("supplier", " "))) Correct answer
Correct Answer:
E. itemsDf.select(size(split("supplier", " ")))
Explanation

Output of correct code block: +----------------------------+ |size(split(supplier, , -1))| +----------------------------+ | 3| | 1| | 3| +----------------------------+ This Question: shows a typical use case for the split command: Splitting a string into words. An additional difficulty is that you are asked to count the words. Although it is tempting to use the count method here, the size method (as in: size of an array) is actually the correct one to use. Familiarize yourself with the split and the size methods using the linked documentation below. More info: Split method: pyspark.sql.functions.split — PySpark 3.1.2 documentation Size method: pyspark.sql.functions.size — PySpark 3.1.2 documentation Static notebook | Dynamic notebook: See test 2,

Scroll to Top