JSON Input and Output
to_json and read_json move data to and from JSON.
Example
import io
df = pd.DataFrame({"a": [1, 2], "b": ["x", "y"]})
s = df.to_json(orient="records")
print(s)
print(pd.read_json(io.StringIO(s)).shape)Result
[{"a":1,"b":"x"},{"a":2,"b":"y"}]
(2, 2)Exercise
Records format.
to_json(orient="")
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.