【发布时间】:2021-05-10 02:04:49
【问题描述】:
Thisexcel文件被转换为json, 但是在 python 中使用 pandas 库,它会明智地执行转换列,并显示为this。 我希望它以以下格式显示:
{"peopleInfo": [
{
"Name": "John",
"UserId": "39048",
"FavoriteWords": [
{
"word": "Sincerity",
"wordInfo": [
{
"meaning": "the quality or state of being sincere",
"language": "English"
},
{
"meaning": "honesty of mind",
"language": "English"
}, and so on....
]
},
{
"word": "Sincerity",
"wordInfo": [
{
"meaning": "the quality or state of being sincere",
"language": "English"
},
{
"meaning": "honesty of mind",
"language": "English"
}
]
}, and so on....
]
},
{
"Name": "Doe",
"UserId": "23749",
"FavoriteWords": [
{
"word": "Fun",
"wordInfo": [
{
"meaning": "what provides amusement or enjoyment",
"language": "English"
},
{
"meaning": "a mood for find or making amusement",
"language": "English"
}
]
},
{
"word": "Sharing",
"wordInfo": [
{
"meaning": "to divide something between two or more people",
"language": "English"
},
{
"meaning": "joint use of a resource or space",
"language": "English"
}
]
}
]
}, and so on....
] }
请不要考虑问题的上下文,我知道它很蹩脚,但我正在研究不同的东西。
【问题讨论】:
-
如果没有一些自定义逻辑,您将无法获得嵌套的 json 格式。如果您不想为每一行输出一个包含一个对象的 json 数组,请执行
pandas.DataFrame.to_json(orient='records')