Basic Human Being Basic Human Being - 1 year ago 173
Python Question

Python 2.7 csv download from URL

I'm trying to do some basic analsys on ether historical prices for a school project. My problem is quite a simple one I think. I made a function that download the data from the URL, but the format is wrong. I got a dataframe thats size is (0,~14k). So I download the data, but I'm not sure how should I format it into a form that I can use.

I see 2 possibilities, I format the dataframe after download, which I will try to do. Or I download it in the correct format first, which would be the better and more elegant solution.

My problem that I don't know how to do the 2. and I may not succeed on the 1. thats why I make this post.

def get_stock_price_csv_from_poloniex():

import requests
from pandas import DataFrame
from io import StringIO

url = ''

csv = requests.get(url)

if csv.ok:
return DataFrame.from_csv(StringIO(csv.text), sep=',')
return None

Thank you for your wisdom!

edited: spelling (?-,)

Answer Source

The source data is not CSV, it's . Luckily pandas provides facilities for working with it as well.

import requests
from import json_normalize

url = ''
resp = requests.get(url)
data_frame = json_normalize(resp.json())
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download