我正在尝试用python把一个嵌套的json内容转换成一个 Dataframe :
{
"end_date":"2023-02-02-00:00",
"price":{
"2023-01-30":{
"CHFEUR":{
"close":0.99612,
"high":0.99939,
"low":0.99408,
"open":0.99925
},
"CHFUSD":{
"close":1.08098,
"high":1.08884,
"low":1.08041,
"open":1.08579
},
"EURUSD":{
"close":1.08518,
"high":1.0914,
"low":1.08393,
"open":1.08609
}
},
"2023-01-31":{
"CHFEUR":{
"close":1.00489,
"high":1.00532,
"low":0.99497,
"open":0.99684
},
"CHFUSD":{
"close":1.09152,
"high":1.09269,
"low":1.0769,
"open":1.08127
},
"EURUSD":{
"close":1.08626,
"high":1.0875,
"low":1.08022,
"open":1.08498
}
},
"2023-02-01":{
"CHFEUR":{
"close":1.00156,
"high":1.00507,
"low":0.9997,
"open":1.00493
},
"CHFUSD":{
"close":1.10089,
"high":1.10213,
"low":1.09005,
"open":1.09204
},
"EURUSD":{
"close":1.09892,
"high":1.10013,
"low":1.08525,
"open":1.08637
}
},
"2023-02-02":{
"CHFEUR":{
"close":1.0037,
"high":1.00633,
"low":0.99968,
"open":1.00113
},
"CHFUSD":{
"close":1.09513,
"high":1.10353,
"low":1.09439,
"open":1.1
},
"EURUSD":{
"close":1.0911,
"high":1.10332,
"low":1.08855,
"open":1.09893
}
}
},
"start_date":"2023-01-30-00:00"
}
这个想法是拉一个 Dataframe :
| 日期|瑞士法郎|瑞士法郎美元|欧元美元|
| - ------|- ------|- ------|- ------|
| 2023年1月30日|0.99925|一点零八五七九|一○八六零九|
| 2023年1月31日|0.99684|一点零八一二七|一点零八四九八|
| 二○二三年二月一日|一○ ○四九三|一○九二零四|一点零八六三七|
| 二○二三年二月二日|一○ ○一一三|1.1节|一○九八九三|
我尝试使用转置,但在此之后,我无法从每个值的内容中拉出值"打开":
x一个一个一个一个x一个一个二个x
关于如何在嵌套的json内容中只提取值"open",你有什么想法吗?
谢谢大家!
3条答案
按热度按时间p8h8hvxi1#
如果你只想用Pandas;-)
hgqdbh6s2#
尝试(
data
包含问题中的字典):图纸:
9bfwbjaz3#
进口Pandas当PD
lst_data =[{'日期':键,'瑞士法郎':物料['瑞士法郎']['未结'],'瑞士法郎美元':物料['瑞士法郎美元']['未结'],'欧元美元':物料['欧元美元']['未结']}对于键,物料在数据中['价格']. items()]
df = pd. Dataframe (lst_data)
打印(df)