A Data Analyst needs to retrieve employees with 5 or more years of tenure.
Which code snippet filters and shows the list?
Suggested Answer: A
Get Premium Databricks Certified Associate Developer for Apache Spark 3.5 Questions
as Interactive Web-Based Practice Test or PDF
Real Exam Format
Detailed Explanations
Instant Access
Get Your Practice Test
To filter rows based on a condition and display them in Spark, use filter(...).show():
employees_df.filter(employees_df.tenure >= 5).show()
Option A is correct and shows the results.
Option B filters but doesn't display them.
Option C uses Python's built-in filter, not Spark.
Option D collects the results to the driver, which is unnecessary if .show() is sufficient.
Final Answer: A
26 comments · newest first
NO
Norah
5 months ago
I feel like C is too vague. It doesn’t specify the DataFrame.
LU
Lucina
5 months ago
Option D is good too, but I don’t need to collect the data.
CA
Carri
6 months ago
I prefer option B. It’s cleaner and still works.
HU
Hubert
6 months ago
I think option A is correct. It shows the data directly.
JU
Justine
6 months ago
I disagree, B is cleaner and more readable!
AS
Ashley
6 months ago
Definitely A, it’s the most straightforward.
MO
Mona
6 months ago
Wait, can you really use .collect() like that?
SA
Santos
6 months ago
I think B is the best choice for clarity.
TA
Tanesha
7 months ago
Option A looks good for showing the results!
AL
Altha
7 months ago
Option B is the way to go, it's the most efficient and readable.
MA
Marvel
7 months ago
Haha, option C is just missing the DataFrame name, what a rookie mistake!
GI
Gianna
8 months ago
Option D seems like the best choice, it returns the full dataset instead of just showing it.
NA
Naomi
8 months ago
I'd go with option A, it's more explicit and easier to understand.
DO
Domitila
8 months ago
Option B looks good, it's clear and concise.
TA
Taryn
8 months ago
I feel like option D is also valid since .collect() would return the results, but I’m not sure if it’s necessary for just filtering.
DO
Dominga
8 months ago
Option C seems incomplete to me; I don't think you can just use filter like that without specifying the DataFrame.
PA
Patti
9 months ago
I remember practicing with the .where() method, so I feel like option B could be correct too.
TH
Theresia
9 months ago
I think option A looks familiar, but I'm not sure if it needs the .show() at the end.
VI
Vivienne
9 months ago
I'd go with option B. It's clear and concise, and the where() method is commonly used for filtering DataFrames.
KE
Kerry
9 months ago
I'm a bit confused by option C. Isn't filter() a DataFrame method, not a standalone function?
LE
Leanna
9 months ago
Option D might be good if I need to store the filtered results in a variable for later use. The collect() method will return a list of the matching rows.
OD
Odette
9 months ago
Hmm, I'm not sure about option A. Does the filter() method return a new DataFrame or just display the results?
NA
Natalya
10 months ago
I think option B looks the most straightforward. Just need to use the where() method to filter the DataFrame.
JA
Janet
3 months ago
I like D for collecting results, but B is simpler for filtering.
KE
Kerry
4 months ago
Option A is also good, but B feels more intuitive.
MA
Mari
5 months ago
I agree, option B is clean and easy to read.