【发布时间】:2021-06-11 07:22:55
【问题描述】:
有一个来自 api 的 json 输入:
{
"api_info": {
"status": "healthy"
},
"items": [
{
"timestamp": "time",
"stock_data": [
{
"ticker": "string",
"industry": "string",
"Description": "string"
}
]
"ISIN":xxx,
"update_datetime": "time"
}
]
}
已经开始运行
apiRawData = requests.get(url).json()['items']
然后运行 json_normalize 方法:
apiExtractedData = pd.json_normalize(apiRawData,'stock_data',errors='ignore')
这是 stock_data 仍包含在列表中的初始输出。 stock_data ISIN update_datetime 0 [{'description': 'zzz', 'industry': 'C', 'ticker...xxx time
| stock_data | ISIN | update_datetime | |
|---|---|---|---|
| 0 | [{'description': 'zzz', 'industry': 'C', 'ticker...] | 123 | time |
我想要实现的是显示标题和相应行的数据框:
| description | industry | ticker | ISIN | update_datetime | |
|---|---|---|---|---|---|
| 0 | 'zzz' | 'C' | xxx | 123 | time |
如果已经回答了现有问题,请指导我:) 干杯。
【问题讨论】:
标签: python-3.x dataframe json-normalize