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

Certified Associate Developer for Apache Spark Exam - Question 57


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

Show Answer
Correct Answer: B

To write a DataFrame to a file as JSON in PySpark, you must use the `write.json` method. The correct code block is `storesDF.write.json(filePath)`. This specifies that the DataFrame `storesDF` should be written to the file path `filePath` in JSON format. Other options either do not follow the correct method signature or structure, making them invalid.

Discussion

2 comments
Sign in to comment
4be8126Option: B
May 3, 2023

The correct answer is B. Explanation: The write method is used to write a DataFrame to a file system in various formats. The json method specifies that the output format should be JSON. The filePath argument specifies the location to write the output file. Option A is incorrect because option requires a key-value pair (e.g., option("key", "value")). Option C is incorrect because path is not a valid option for write. Option D is incorrect because write method requires a format argument to specify the output format. Option E is a valid option, but the parentheses after write are unnecessary.

juliom6Option: B
Nov 14, 2023

B is correct according documentation: https://spark.apache.org/docs/latest/api/python/reference/pyspark.sql/api/pyspark.sql.DataFrameWriter.json.html