nerdexam
Databricks

DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #19

Which of the following code blocks returns all the rows from DataFrame storesDF?

The correct answer is B. storesDF.collect(). DataFrame.collect() is the PySpark action that retrieves all rows from the distributed DataFrame and returns them to the driver as a Python list of Row objects. The other options do not return all rows: head() (A) returns only the first row (or first n rows); count() (C) returns

Performing Spark DataFrame Actions

Question

Which of the following code blocks returns all the rows from DataFrame storesDF?

Options

  • AstoresDF.head()
  • BstoresDF.collect()
  • CstoresDF.count()
  • DstoresDF.take()
  • EstoresDF.show()

How the community answered

(34 responses)
  • B
    91% (31)
  • D
    6% (2)
  • E
    3% (1)

Explanation

DataFrame.collect() is the PySpark action that retrieves all rows from the distributed DataFrame and returns them to the driver as a Python list of Row objects. The other options do not return all rows: head() (A) returns only the first row (or first n rows); count() (C) returns an integer count of rows, not the rows themselves; take(n) (D) requires an integer argument and returns only the first n rows; and show() (E) prints a formatted table to the console and returns None - it does not return the row data.

Topics

#Spark DataFrame#DataFrame Actions#Data Retrieval#PySpark API

Community Discussion

No community discussion yet for this question.

Full DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK Practice