
Answer-first summary for fast verification
Answer: 1. withColumn 2. "productCategories" 3. explode 4. col 5. "productCategories"
The task requires transforming the `productCategories` column so that each element in the array becomes a separate row, effectively increasing the number of rows in the DataFrame. The correct approach involves using the `explode` function on the `productCategories` column. This is achieved by first selecting the column with `col`, then applying `explode` to it, and finally using `withColumn` to replace the original column with the exploded values. Option E correctly follows this sequence: `withColumn` is used to create or replace the column, `explode` is the function applied to transform the array into rows, and `col` is used to reference the `productCategories` column. This results in a DataFrame where each row contains a single word from the original arrays in the `productCategories` column.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
The code block below should transform the DataFrame storesDF such that the productCategories column contains only one word per row, resulting in a DataFrame with significantly more rows than the original.
Select the option that correctly fills in the numbered blanks to achieve this transformation.
Question Code block:
storesDF.__1__(__2__, __3__(__4__(__5__)))
A sample of storesDF is shown:
| storeld | productCategories |
|---|---|
| 0 | netus, pellentes... |
| 1 | consequat enim,... |
| 2 | massa, a, vitae,... |
| 3 | aliquam, donec... |
| 4 | condimentum, fer... |
| 5 | viverra habitan... |
A
B
C
D
E