请帮助我解决我的问题...我正在尝试转换我的 Dataframe 到json和添加外部json。
technologies = {
'rid':[1000208,1000209,11111],
'num' :[1,2,3],
'cid':[10002,10003,10000]
}
df = pd.DataFrame(technologies)
print(df)
json_res=df.to_json(orient="records")
print(json_res)
[{“编号”:1000208,“编号”:1,“代码”:10002},{“编号”:1000209,“编号”:2,“代码”:10003},{“编号”:11111,“编号”:3,“代码”:10000}]
...只想添加关键字key_word =“report_result”预期结果[{“report_result”:[{“编号”:1000208,“编号”:1,“代码”:10002},{“编号”:1000209,“编号”:2,“代码”:10003},{“编号”:11111,“编号”:3,“代码”:10000}]
1条答案
按热度按时间yqlxgs2m1#
要将外部JSON对象添加到 Dataframe 的JSON表示中,可以使用
json.dumps
函数并将df.to_json(orient="records")
的结果作为输入传递。产出将是: