Reading csv from url

I have the following csv url that works correctly if simply pasted into the browser:

http://www.google.com/finance/historical?q=JSE%3AMTN&startdate=Nov 1, 2011&enddate=Nov 30, 2011&output=csv

However, I cannot load csv using pandas. I get an error message:

urllib.error.HTTPERROR: HTTP ERROR 400: Bad Request

the code:

import pandas as pd

def main():

    url = 'http://www.google.com/finance/historical?q=JSE%3AMTN&startdate=Nov 1, 2011&enddate=Nov 30, 2011&output=csv'

    df = pd.read_csv(url)
    print(df)

Please can someone point me in the right direction.

+4
source share
1 answer

This URL is incorrectly encoded. Your browser automatically replaces spaces ' 'with '%20'; a basic urllibrequest from the python standard library does not. Replace all spaces with '%20', and everything is fine.

, pandas 0,16, , Google Finance (. http://pandas.pydata.org/pandas-docs/stable/remote_data.html#remote-data-google):

import pandas.io.data as web

df = web.DataReader("F", 'JSE:MTN', "2011-11-01", "2011-11-30")
+3

All Articles