Certified Associate Developer for Apache Spark Exam QuestionsBrowse all questions from this exam

Certified Associate Developer for Apache Spark Exam - Question 37


Which of the following code blocks returns a 15 percent sample of rows from DataFrame storesDF without replacement?

Show Answer
Correct Answer: E

To return a 15 percent sample of rows from DataFrame storesDF without replacement, you should use the sample method with the fraction parameter set to 0.15. This specifies that 15 percent of the DataFrame's rows are to be randomly sampled. Since the default behavior of sample() is without replacement, setting the fraction to 0.15 directly addresses the requirement.

Discussion

1 comment
Sign in to comment
4be8126Option: E
Apr 26, 2023

The answer is E. Option A returns a 10% sample, not a 15% sample as requested. Option B is incorrect because sampleBy() is used to perform stratified sampling based on a column's values. Option C is incorrect because the first argument should be set to False to prevent sampling with replacement. Option D is incorrect because the sample() method without arguments will return a 50% sample of the DataFrame. Option E is the correct answer as it returns a sample of 15% of the DataFrame without replacement.