我正在使用 df.to_json()
将数据框转换为 Json 格式。但是它给出的是一个 Json 字符串而不是一个对象。
如何获取 Json 对象?
此外,当我将这些数据添加到一个数组中时,它在 json 的前后添加了单引号,破坏了 json 结构。
如何导出为 Json 对象并正确地添加到数组中?
使用的代码:
a=[]
array.append(df1.to_json(orient='records', lines=True))
array.append(df2.to_json(orient='records', lines=True))
结果:
['{"test:"w","param":1}','{"test:"w2","param":2}]']
所需结果:
[{"test":"w","param":1},{"test":"w2","param":2}]
谢谢!
df.to_dict()
。 - ted