
Answer-first summary for fast verification
Answer: storesDF.sample(true, fraction = 0.1)
The question asks for a 10% sample with replacement. The `sample` method in PySpark requires `withReplacement` (boolean) and `fraction` (float). Option B uses `true` (with replacement) and `fraction=0.1` (10%). Option A is incorrect because it omits the fraction (defaults to 1.0, 100% sample). Option C uses 0.15 (15%). Option D uses `sampleBy`, which requires stratified sampling parameters. Option E uses `false` (no replacement). Thus, only B meets the criteria.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
Which of the following code blocks returns a 10% sample of rows from DataFrame storesDF with replacement?
A
storesDF.sample(true)
B
storesDF.sample(true, fraction = 0.1)
C
storesDF.sample(true, fraction = 0.15)
D
storesDF.sampleBy(fraction = 0.1)
E
storesDF.sample(false, fraction = 0.1)
No comments yet.