Search code examples
pythonpandasfinance

How to Read and Format a Weblink .csv with Python Pandas


I am learning Pandas, and trying to download a .csv from Morningstar with the Morningstar API.

There are some very well put together instructions on how to use the API have been provided here (although they are not Python specific)... https://gist.github.com/hahnicity/45323026693cdde6a116

The sample weblink is that hahnicity uses in the example is: http://globalquote.morningstar.com/globalcomponent/RealtimeHistoricalStockData.ashx?ticker=F&showVol=true&dtype=his&f=d&curry=USD&range=1900-1-1|2014-10-10&isD=true&isS=true&hasF=true&ProdCode=DIRECT

My code is:

import pandas as pd    
path='http://globalquote.morningstar.com/globalcomponent/RealtimeHistoricalStockData.ashx?ticker=F&showVol=true&dtype=his&f=d&curry=USD&range=1900-1-1|2014-10-10&isD=true&isS=true&hasF=true&ProdCode=DIRECT'

df=pd.read_csv(path)

However, what is returned is gibberish. I am not sure how to make Pandas read this in the correct columnar form?

Any help is greatly appreciated. Thank you in advance!


Solution

  • Okay, so I do not understand how to handle the JSON format that is stored as a .csv with Pandas... so I decided to use Quandl instead. It solves my problem.

    import pandas as pd
    df=pd.read_csv('https://www.quandl.com/api/v3/datasets/WIKI/<ticker_symbol>/data.csv?api_key=<api_key>')
    

    This returns the end of day pricing for the ticker in question.

    You can find there docs and register for an API key here: (https://docs.quandl.com/docs/in-depth-usage).