【发布时间】:2021-04-12 09:57:45
【问题描述】:
我有一个像这样非常混乱的 JSON 对象 -
{
"LDL Cholesterol": {
"displayName": {
"en": "LDL Cholesterol",
"hi": "kls"
},
"sliderType": "NHHHH",
"high": 160,
"text": {
"en": "LDL",
"hi": "ldd"
}
},
"HDL/LDL Cholesterol Ratio": {
"displayName": {
"en": "HDL : LDL ratio",
"hi": "klas"
},
"sliderType": "LN",
"lowThresh": 0.33,
"text": {
"en": "",
"hi": "jla"
}
}
}
我想要这样的excel表格-
Test Name |sliderType|high|lowThresh|en.displayName |en.text|hi.displayName|hi.text
LDL Cholesterol | NHHHH |160 | |LDL Cholesterol| LDL | kls |ldd
HDL/LDL Cholesterol Ratio| LN | | 0.33 |HDL : LDL ratio| | klas |jla
我尝试在 json_normalize 的帮助下将其转换为 pandas 数据框,但它仅在 1 行中显示所有数据。 这是使用的代码
f=open('path_to_file','rb')
data = json.load(f)
df = pandas.json_normalize(data)
我尝试使用 swapLevel、重新排序等,但没有成功。 我是 Python 的初学者。请帮忙!
【问题讨论】:
-
发布您的代码,以便我们查看问题所在。
标签: python json excel pandas dataframe