我有以下嵌套的json:
import requests
headers = {
'Content-Type': 'application/json'
}
r = requests.get("...API DATA...")
[
{
"ticker":"btcusd",
"baseCurrency":"btc",
"quoteCurrency":"usd",
"priceData":[
{
"open":3914.749407813885,
"high":3942.374263716895,
"low":3846.1755315352952,
"close":3849.1217299601617,
"date":"2019-01-02T00:00:00+00:00",
"tradesDone":756.0,
"volume":339.68131616889997,
"volumeNotional":1307474.735327181
}
]
}
]
我想把它转换成熊猫数据帧。我已经能够做到这一点:
j = r.json()
df = pd.DataFrame.from_dict(j)
df
输出:
我还想在列中展开“priceData”
我尝试了不同的方法,包括json.normalise和json.loads,但总有一个错误我无法理解
谁能告诉我怎么做才能理解吗
谢谢
编辑
priceData包含多个元素
数据帧中基本上不需要“ticker”、“baseCurrency”和“quoteCurrency”,因此可以丢弃
使用
json_normalize
:在哪里,
编辑:用于多个API调用
相关问题 更多 >
编程相关推荐