Complete the code to export the DataFrame to a JSON file named 'data.json'.
df.to_json('[1]')
The to_json method saves the DataFrame as a JSON file. The filename must end with .json.
Complete the code to export the DataFrame to a JSON string instead of a file.
json_str = df.to_json([1]=None)
Setting path_or_buf=None returns the JSON as a string instead of saving to a file.
Fix the error in the code to export only the 'name' and 'age' columns to JSON.
df[['name', '[1]']].to_json('subset.json')
To export 'name' and 'age' columns, both must be selected. The missing column is 'age'.
Fill both blanks to export the DataFrame to JSON with records orientation and indentation of 2 spaces.
df.to_json('output.json', orient='[1]', indent=[2])
Setting orient='records' outputs JSON as a list of records. indent=2 formats JSON with 2 spaces indentation.
Fill all three blanks to export the DataFrame to JSON with index excluded, using split orientation, and ASCII characters only.
df.to_json('final.json', [1]=False, orient='[2]', force_ascii=[3])
Setting index=False excludes the index from JSON. orient='split' formats JSON with separate keys for index, columns, and data. force_ascii=True ensures ASCII characters only.