我有一个现有的json文件,格式为字典列表。
$cat output.json
[{'a':1, 'b':2}, {'a':2, 'b':3}]
我有一个数据框
df = pd.DataFrame({'a':pd.Series([1,2], index=list('CD')), \
"b":pd.Series([3,4], index=list('CD')})
我希望使用 to_json 将“df”保存并追加到文件 output.json 中:
df.to_json('output.json', orient='records') # mode='a' not available for to_json
* to_csv 有 append mode='a',但是 to_json 真的没有。
期望生成的 output.json 文件将会是:
[{'a':1, 'b':2}, {'a':2, 'b':3}, {'a':1, 'b':3}, {'a':2, 'b':4}]
现有的输出文件output.json可能非常大(比如说以太字节),是否有可能在不加载文件的情况下追加新的数据框结果?