我在json下面,我从一些网址获得:
{
"abc":
{
"123":[45600,null,3567],
"378":[78689,2345,5678],
"343":[23456,null,null]
}
}
它存储在json_obj对象中:
json_obj = response.json()
我需要将这个json转换为数据帧,我的代码应该是这样的:
df = pd.read_json(response,orient ='columns')
所以,结果应该是:
abc
123 [45600,null,3567]
378 [78689,2345,5678]
343 [23456,null,null]
但是上面的代码我得到错误:
date_unit).parse()
self._parse_no_numpy()
loads(json, precise_float=self.precise_float), dtype=None)
TypeError: Expected String or Unicode
请提出建议。
答案 0 :(得分:1)
df = pd.read_json(response,orient='columns')
read_json()接受JSON数据。 "响应",我相信会为您正在制作的某些请求存储API响应。
response.json()会给你响应主体的python字典。 您需要将其转换为JSON。 试试这个:
import json
df = pd.read_json(json.dumps(response.json()),orient='columns')