nerdexam
Databricks

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

Which of the following operations can be used to return the number of rows in a DataFrame?

The correct answer is D. DataFrame.count(). DataFrame.count() is the standard PySpark action that triggers a full scan of the DataFrame and returns the total number of rows as a Python integer. The other options do not exist or serve different purposes: numberOfRows() (A) and n() (B) are not PySpark DataFrame methods…

Working with Spark DataFrames

Question

Which of the following operations can be used to return the number of rows in a DataFrame?

Options

  • ADataFrame.numberOfRows()
  • BDataFrame.n()
  • CDataFrame.sum()
  • DDataFrame.count()
  • EDataFrame.countDistinct()

How the community answered

(61 responses)
  • B
    2% (1)
  • C
    7% (4)
  • D
    89% (54)
  • E
    3% (2)

Explanation

DataFrame.count() is the standard PySpark action that triggers a full scan of the DataFrame and returns the total number of rows as a Python integer. The other options do not exist or serve different purposes: numberOfRows() (A) and n() (B) are not PySpark DataFrame methods; sum() (C) aggregates numeric column values, not row counts; and countDistinct() (E) is a SQL function used inside aggregations to count distinct values in a column, not a top-level DataFrame method that counts rows.

Topics

#Spark DataFrame#DataFrame operations#Count rows#API methods

Community Discussion

No community discussion yet for this question.

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