python - Parsing JSON data from an API to Pandas -


i trying data api ( https://min-api.cryptocompare.com/data/histoday?fsym=btc&tsym=eth&limit=30&aggregate=1&e=cccagg ) pandas. api gives data in json.

df = pd.read_json('new.json' , orient = 'columns') 

error: mixing dicts non-series may lead ambiguous ordering.

data need:- image link : http://imgur.com/a/bdln8

i new this, fantastic.

i believe issue you're passing entirety of json read_json function, when should passing data stored in data attribute.


if you're downloading data programmatically, recommend requests:

in [422]: import requests  in [416]: data = requests.get('https://min-api.cryptocompare.com/data/histoday?fsym=btc&tsym=eth&limit=30&aggregate=1&e=cccagg')\                          .json()['data'] 

data dictionary, not json string. can call pd.dataframe.from_dict function parse data, this:

in [420]: df = pd.dataframe.from_dict(data)  in [421]: df.head() out[421]:     close   high    low   open        time  volumefrom   volumeto 0  12.29  11.55  12.73  12.54  1500595200    72064.93  875383.96 1  12.22  11.93  12.61  12.29  1500681600    39624.40  489345.17 2  12.03  11.94  12.37  12.22  1500768000    37270.80  452462.43 3  12.22  11.99  12.36  12.03  1500854400    28582.22  347606.39 4  12.59  12.22  13.03  12.22  1500940800    54004.34  676716.41 

if insist on using pd.from_json, must pass string data contained inside data attribute of json response, otherwise not work.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -