Я пытался получить данные из API и преобразовать их в Pandas DataFrame.
Однако после чтения данных из API я не могу преобразовать ответ в JSON.
import pandas as pd
import numpy as np
import requests
import json
r = requests.get('https://api.rootnet.in/covid19-in/')
x = r.json()
print(type(x))
df = pd.DataFrame(x['teams'])
df
ошибка:
JSONDecodeError Traceback (most recent call last)
<ipython-input-13-e2dd33599256> in <module>()
5
6 r = requests.get('https://api.rootnet.in/covid19-in/')
----> 7 x = r.json()
8 print(type(x))
9 df = pd.DataFrame(x['teams'])
~/anaconda3/lib/python3.7/site-packages/requests/models.py in json(self, **kwargs)
894 # used.
895 pass
--> 896 return complexjson.loads(self.text, **kwargs)
897
898 @property
~/anaconda3/lib/python3.7/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
346 parse_int is None and parse_float is None and
347 parse_constant is None and object_pairs_hook is None and not kw):
--> 348 return _default_decoder.decode(s)
349 if cls is None:
350 cls = JSONDecoder
~/anaconda3/lib/python3.7/json/decoder.py in decode(self, s, _w)
338 end = _w(s, end).end()
339 if end != len(s):
--> 340 raise JSONDecodeError("Extra data", s, end)
341 return obj
342
JSONDecodeError: Extra data: line 1 column 5 (char 4)
Сведения об API: https://www.programmableweb.com/api/covid-19-india-rest-api-v10