October 2019
Beginner to intermediate
674 pages
16h 43m
English
The to_json() function allows any DataFrame object to be converted into a JSON string or written to a JSON file if the file path is specified:
df = pd.DataFrame({"Col1": [1, 2, 3, 4, 5], "Col2": ["A", "B", "B", "A", "C"], "Col3": [True, False, False, True, True]})df.to_json()
Take a look at the following output:
The orientation of the data in the JSON can be altered. The to_json() function has an orient argument which can be set for the following modes: columns, index, record, value, and split. Columns is the default setting for orientation:
df.to_json(orient="columns")
Take a look at the following ...
Read now
Unlock full access