この回答が示唆するよう.to_json()
に、関数とdefault_handler
パラメーターを使用してデータフレームを変換しました。ドキュメントはこちらにあります。
default_handler=str
上記のエラーが発生しないように、パラメーターに注意を払う必要があります。上記のドキュメントで詳細を読むことができます。
dataframe.to_json('foo.json', default_handler=str)
ドキュメントにあるように、関数がjson
さまざまな方法で出力できることを忘れないでください。パラメーターはそれを指定します。orient='<option>'
orient: str
Indication of expected JSON string format.
...
The format of the JSON string:
- ‘split’ : dict like {‘index’ -> [index], ‘columns’ -> [columns], ‘data’ -> [values]}
- ‘records’ : list like [{column -> value}, … , {column -> value}]
- ‘index’ : dict like {index -> {column -> value}}
- ‘columns’ : dict like {column -> {index -> value}}
- ‘values’ : just the values array
- ‘table’ : dict like {‘schema’: {schema}, ‘data’: {data}}
Describing the data, where data component is like orient='records'.