【发布时间】:2022-01-09 18:40:56
【问题描述】:
我想就我拥有的这个 .json 文件寻求一些帮助。 我已经广泛地查看了 pd.json_normalize() 方法,但我无法正确设置格式。
我正试图尝试的代码行是这样的 ''' result_df = pd.json_normalize(cgcryptohistory_data) '''
我很想把我的 json 格式化成一个格式如下的 df:
| date | bitcoin prices | bitcoin market_caps | bitcoin total_volumes | ethereum prices | ethereum market_caps | ethereum total_volumes | |
|---|---|---|---|---|---|---|---|
| 1637920962758 | 55084.24409740329 | 1040185692035.8112 | 4096.986983019884 | ... | ... | ||
| 1637924583096 | ... | ... | ... | ... | ... | ... |
我一直在查看此文档,但无法使其与未命名的嵌套值一起使用。 https://pandas.pydata.org/pandas-docs/version/1.2.0/reference/api/pandas.json_normalize.html https://www.kaggle.com/jboysen/quick-tutorial-flatten-nested-json-in-pandas/notebook
[
[
{
"crypto": "bitcoin"
}
],
{
"prices": [
[
1637920962758,
55084.24409740329
],
[
1637924583096,
54657.9826454445
],
[
1637928143387,
54031.99796233907
],
[
1638524408000,
56556.355173823926
]
],
"market_caps": [
[
1637920962758,
1040185692035.8112
],
[
1637924583096,
1032137732028.0712
],
[
1637928143387,
1020318960913.6139
],
[
1638524408000,
1068341065780.2579
]
],
"total_volumes": [
[
1637920962758,
40002799175.46155
],
[
1637924583096,
38579701553.8867
],
[
1637928143387,
39373185822.85809
],
[
1638524408000,
32567680716.236423
]
]
},
[
{
"crypto": "ethereum"
}
],
{
"prices": [
[
1637920951704,
4096.986983019884
],
[
1637924408082,
4072.6963895955864
],
[
1637928090810,
4021.2930336538925
],
[
1638524390000,
4559.839444343959
]
],
"market_caps": [
[
1637920951704,
485474079335.9266
],
[
1637924408082,
482758573953.61304
],
[
1637928090810,
479260985689.3548
],
[
1638524390000,
540740261905.95264
]
],
"total_volumes": [
[
1637920951704,
25972933719.35031
],
[
1637924408082,
26468521371.13646
],
[
1637928090810,
27042124946.11916
],
[
1638524390000,
20268892519.524815
]
]
}
]
【问题讨论】: