Which of the following code blocks writes DataFrame storesDF to file path filePath as JSON?
Which of the following code blocks writes DataFrame storesDF to file path filePath as JSON?
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.
B is correct according documentation: https://spark.apache.org/docs/latest/api/python/reference/pyspark.sql/api/pyspark.sql.DataFrameWriter.json.html
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.