概要
pandas.to_jsonの挙動を調べてみた。
サンプルコード
import pandas as pd
df = pd.DataFrame([['a0', 'b0', 'c0'], ['a1', 'b1', 'c1']], index = ['taro', 'jiro'], columns = ['sono1', 'sono2', 'sono3'])
print (df.to_json(orient = 'split'))
print (df.to_json(orient = 'records'))
print (df.to_json(orient = 'index'))
print (df.to_json(orient = 'columns'))
print (df.to_json(orient = 'values'))
結果
{"columns":["sono1","sono2","sono3"],"index":["taro","jiro"],"data":[["a0","b0","c0"],["a1","b1","c1"]]}
[{"sono1":"a0","sono2":"b0","sono3":"c0"},{"sono1":"a1","sono2":"b1","sono3":"c1"}]
{"taro":{"sono1":"a0","sono2":"b0","sono3":"c0"},"jiro":{"sono1":"a1","sono2":"b1","sono3":"c1"}}
{"sono1":{"taro":"a0","jiro":"a1"},"sono2":{"taro":"b0","jiro":"b1"},"sono3":{"taro":"c0","jiro":"c1"}}
[["a0","b0","c0"],["a1","b1","c1"]]
成果物
以上。