nerdexam
Databricks

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

Which of the following code blocks writes DataFrame storesDF to file path filePath as CSV?

The correct answer is C. storesDF.write.csv(filePath). C is correct because in PySpark, write is a property (not a method), returning a DataFrameWriter object, and .csv(filePath) is the correct format-specific method to both specify the format and trigger the write. Why the distractors fail: A - write() with parentheses is invalid…

DataFrame Data Writing and Serialization

Question

Which of the following code blocks writes DataFrame storesDF to file path filePath as CSV?

Options

  • AstoresDF.write().csv(filePath)
  • BstoresDF.write(filePath)
  • CstoresDF.write.csv(filePath)
  • DstoresDF.write.option("csv").path(filePath)
  • EstoresDF.write.path(filePath)

How the community answered

(23 responses)
  • C
    87% (20)
  • D
    4% (1)
  • E
    9% (2)

Explanation

C is correct because in PySpark, write is a property (not a method), returning a DataFrameWriter object, and .csv(filePath) is the correct format-specific method to both specify the format and trigger the write.

Why the distractors fail:

  • A - write() with parentheses is invalid; write is a property, not a callable method, so this raises an AttributeError.
  • B - write(filePath) has the same parentheses problem and also skips specifying the format entirely.
  • D - There is no .option("csv") shorthand for format selection; .option() is used for key-value settings like header or delimiter, not format specification.
  • E - .path() is not a method on DataFrameWriter; the format method (.csv(), .json(), .parquet()) takes the path as its argument.

Memory tip: Think of it as a two-part chain - property then format+path: df.write.csv(path). If you see parentheses after write, it's wrong; if you see the format and path separated into different calls, it's wrong.

Topics

#DataFrame I/O#CSV writing#Write API#Data serialization

Community Discussion

No community discussion yet for this question.

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