
Answer-first summary for fast verification
Answer: df.repartition(12)
To create a DataFrame with 12 partitions from an existing DataFrame with 8 partitions, the key is to use operations that can increase the partition count. - **Option A (df.repartition(12))** is correct because `repartition` triggers a full shuffle and can increase or decrease the number of partitions to the specified value (12 here). - **Option D (df.coalesce(12))** is incorrect because `coalesce` can only reduce the number of partitions. If the target is larger than the current partition count (8 → 12), it leaves the DataFrame unchanged. - **Options B, C, E** are invalid: `cache()` does not alter partitions, `partitionBy` is not a DataFrame method (used in writing data), and partition counts must be integers.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
Which of the following operations can be used to create a new DataFrame with 12 partitions from an original DataFrame df that currently has 8 partitions?
A
df.repartition(12)
B
df.cache()
C
df.partitionBy(1.5)
D
df.coalesce(12)
E
df.partitionBy(12)