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…
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)- C87% (20)
- D4% (1)
- E9% (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;writeis a property, not a callable method, so this raises anAttributeError. - 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 likeheaderordelimiter, not format specification. - E -
.path()is not a method onDataFrameWriter; 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
Community Discussion
No community discussion yet for this question.