DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #18
Which of the following code blocks returns a 15 percent sample of rows from DataFrame storesDF without replacement?
The correct answer is E. storesDF.sample(fraction = 0.15). storesDF.sample(fraction=0.15) is correct: the fraction parameter specifies the proportion of rows to sample (0.15 = 15%), and the withReplacement parameter defaults to False, meaning sampling is done without replacement. Option A uses fraction=0.10 (10%, not 15%). Option B…
Question
Which of the following code blocks returns a 15 percent sample of rows from DataFrame storesDF without replacement?
Options
- AstoresDF.sample(fraction = 0.10)
- BstoresDF.sampleBy(fraction = 0.15)
- CstoresDF.sample(True, fraction = 0.10)
- DstoresDF.sample()
- EstoresDF.sample(fraction = 0.15)
How the community answered
(23 responses)- A4% (1)
- D4% (1)
- E91% (21)
Explanation
storesDF.sample(fraction=0.15) is correct: the fraction parameter specifies the proportion of rows to sample (0.15 = 15%), and the withReplacement parameter defaults to False, meaning sampling is done without replacement. Option A uses fraction=0.10 (10%, not 15%). Option B uses sampleBy(), which is a stratified sampling method with a different parameter structure. Option C uses True for withReplacement (i.e., with replacement) and the wrong fraction. Option D passes no arguments, which is invalid. Only E correctly specifies 15% without replacement.
Topics
Community Discussion
No community discussion yet for this question.