Skip to main content

Load

Create sample DataFrame

import pandas as pd

columns = ["Name", "Age", "Height"]
data = [
["Ted", 24, 177],
["Judy", 27, 183],
]

df = pd.DataFrame(data=data, columns=columns)

Untitled

Save as CSV

Untitled

Save as JSON

  • default

    df.to_json('./test_pandas_default.json')
    {"Name":{"0":"Ted","1":"Judy"},"Age":{"0":24,"1":27},"Height":{"0":177,"1":183}}
  • columns

    df.to_json('./test_pandas_columns.json', orient="columns")
    {"Name":{"0":"Ted","1":"Judy"},"Age":{"0":24,"1":27},"Height":{"0":177,"1":183}}
  • records

    df.to_json('./test_pandas_records.json', orient="records")
    [{"Name":"Ted","Age":24,"Height":177},{"Name":"Judy","Age":27,"Height":183}]
  • index

    df.to_json('./test_pandas_index.json', orient="index")
    {"0":{"Name":"Ted","Age":24,"Height":177},"1":{"Name":"Judy","Age":27,"Height":183}}
  • split

    df.to_json('./test_pandas_split.json', orient="split")
    {"columns":["Name","Age","Height"],"index":[0,1],"data":[["Ted",24,177],["Judy",27,183]]}
  • table

    df.to_json('./test_pandas_table.json', orient="table")
    {"schema":{"fields":[{"name":"index","type":"integer"},{"name":"Name","type":"string"},{"name":"Age","type":"integer"},{"name":"Height","type":"integer"}],"primaryKey":["index"],"pandas_version":"1.4.0"},"data":[{"index":0,"Name":"Ted","Age":24,"Height":177},{"index":1,"Name":"Judy","Age":27,"Height":183}]}