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

Certified Associate Developer for Apache Spark Exam - Question 79


Which of the following code blocks returns the first 3 rows of DataFrame storesDF?

Show Answer
Correct Answer: CD

The correct method to return the first 3 rows of a DataFrame is head(3). The head(n) method is specifically designed to return the first n rows of the DataFrame in a straightforward and intuitive manner. Although take(3) could also be technically correct, it usually returns the rows as a list, whereas head(3) returns them in the form of a DataFrame, making it the more appropriate and commonly used method for this purpose.

Discussion

4 comments
Sign in to comment
ryanmuOption: D
Jun 23, 2023

Correct answer is D. head(n) returns the first n rows and take(n) returns first n rows as a list

zozoshanky
Jul 30, 2023

Both head and take gives list as an output , am confused need to do more investigation

cookiemonster42Option: C
Aug 1, 2023

C, D and even E are correct. There's no requirement to return a dataframe in the question

azure_bimonsterOption: D
Feb 9, 2024

odd question indeed. head() and take() methods perform a similar operation of retrieving rows from the beginning of the DataFrame. However, head() may be slightly slower than take() due to additional checks for boundary conditions. I can't see the difference in terms of retrieving 1st three rows.

newusernameOption: D
Sep 10, 2023

weird question, taking into account that head essentially calls take on the DataFrame.