我正在尝试根据收到的JSON代码创建一个DataFrame。我以为这很简单,但是我遇到了问题!。
我尝试了类似read.json或normalize.json的尝试,但似乎没有用。我得到的最新错误是:
TypeError: byte indices must be integers or slices, not str
JSON:
b'{"coin":{"id":363,"name":"Bitcoin","code":"BTC"},
"dataType":"marketCap","baseCurrency":"USD",
"data":[{"date":"2018-01-12","marketCap":"232547809668.32000000"},
{"date":"2018-01-13","marketCap":"241311607656.32000000"},
{"date":"2018-01-14","marketCap":"231991232624.24000000"}
代码:
http = urllib3.PoolManager()
url = 'https://www.cryptocurrencychart.com/api/coin/history/363/2018-01-12/2019-01-12/marketCap/USD'
headers = urllib3.util.make_headers(basic_auth='xx, xx')
r = http.request('GET', url , headers = headers)
result = r.data
df = pd.DataFrame(result['data'])
目标: 我想创建一个DataFrame,索引是日期,市值列。