我想将JSON转换为TSV,但不是从文件转换为文件。
messages = {
"1":[
{
"id":"4d9edf9b-ab9a-45bc-a453-3ea9ecc97818",
"message":"m1",
"access": "*"
},
{
"id":"7c4b41e4-3e4f-40ed-9aa4-3854a6b3706a",
"message":"m2",
"access": "*"
},
{
"id":"c1c332cf-7cb4-4c5e-bf85-3d7ae3a11625",
"message":"m3",
"access": "*"
},
{
"id":"dc9b47b9-d325-475d-9994-a4269faa0873",
"message":"m4",
"access": "*"
}
]
}
> import sys
> import pandas as pd
> table = pd.read_json(messages[1], orient='records')
> table.to_csv(sys.stdout, sep='t', index=False)
我试过这样的东西,但它没有工作。请帮帮我
要将Json列表转换为DataFrame,您应该
table=pd.DataFrame.from_records(messages["1"])
然后保存为您在帖子。