DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #158
The code block shown below should return a 25 percent sample of rows from DataFrame storesDF with reproducible results. Choose the response that correctly fills in the numbered blanks within the…
The correct answer is C. 1. sample. The PySpark DataFrame sample() method accepts a fraction parameter (a float between 0.0 and 1.0) and a seed parameter (an integer). Setting a seed makes the sampling deterministic and reproducible across runs. The correct full expression is: storesDF.sample(fraction=0.25…
Question
The code block shown below should return a 25 percent sample of rows from DataFrame storesDF with reproducible results. Choose the response that correctly fills in the numbered blanks within the code block to complete this task. Code block:
StoresDF.1(2 = 3, 4 = 5)
Options
- A
- sample
- B
- sample
- C
- sample
- D
- sample
- E
- sample
How the community answered
(24 responses)- B13% (3)
- C79% (19)
- D4% (1)
- E4% (1)
Explanation
The PySpark DataFrame sample() method accepts a fraction parameter (a float between 0.0 and 1.0) and a seed parameter (an integer). Setting a seed makes the sampling deterministic and reproducible across runs. The correct full expression is: storesDF.sample(fraction=0.25, seed=<integer>). All five choices share blank 1 = 'sample', so the distinguishing factor is filling in fraction=0.25 and seed=<some integer>. Option C is the only one that correctly specifies both the fraction value of 0.25 (25%) and includes a seed for reproducibility.
Topics
Community Discussion
No community discussion yet for this question.