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

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

    Correct Answer: D

    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
ryanmuOption: D

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

zozoshanky

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

azure_bimonsterOption: D

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.

cookiemonster42Option: C

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

newusernameOption: D

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