栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

将JSON API响应转换为pandas Dataframe

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

将JSON API响应转换为pandas Dataframe

我认为您需要

json_normalize

from pandas import json_normalizedf = json_normalize(d, 'abc')print (df)        amount     price      tid   timestamp type0  2321.379525  0.000062  8577050  1498649162  bid1   498.789936  0.000062  8577047  1498649151  bid

对于多个键,可以

concat
listcomprehension
and
Dataframe
构造函数一起使用:

d =  {'abc': [{'type': 'bid', 'price': 6.194e-05, 'amount': 2321.37952545, 'tid': 8577050, 'timestamp': 1498649162}, {'type': 'bid', 'price': 6.194e-05, 'amount': 498.78993587, 'tid': 8577047, 'timestamp': 1498649151}],      'def': [{'type': 'bid', 'price': 6.194e-05, 'amount': 2321.37952545, 'tid': 8577050, 'timestamp': 1498649162}, {'type': 'bid', 'price': 6.194e-05, 'amount': 498.78993587, 'tid': 8577047, 'timestamp': 1498649151}]}

df = pd.concat([pd.Dataframe(v) for k,v in d.items()], keys=d)print (df) amount     price      tid   timestamp typeabc 0  2321.379525  0.000062  8577050  1498649162  bid    1   498.789936  0.000062  8577047  1498649151  biddef 0  2321.379525  0.000062  8577050  1498649162  bid    1   498.789936  0.000062  8577047  1498649151  bid


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/669244.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号