Cannot fetch data from yahoo finance, on google collaboratory

Question:

I know there has been a change on Yahoo finance for fetching data but I dont know how to fix it for my program on google collaboratory. To get the data I am using this code:

    df = web.DataReader('AAPL', data_source='yahoo', start='2012-01-01', end='2021-04-15')
    df

I then get an error saying cannot fetch code, is there any fixes or an alternative I can use?
This is the error:

RemoteDataError Traceback (most recent call last)
in ()
—-> 1 df = web.DataReader(‘AAPL’, data_source=’yahoo’, start=’2012-01-01′, end=’2021-04-15′)
2 df

Asked By: WILLIAM INGLE

||

Answers:

Upgrade your pandas_datareader to .10 (pip install pandas_datareader --upgrade)

With pdr 0.9 you’ll get:

---------------------------------------------------------------------------
RemoteDataError                           Traceback (most recent call last)
<ipython-input-47-de79fadf5dea> in <module>
      1 import pandas_datareader as pdr
----> 2 df = pdr.DataReader('AAPL', data_source='yahoo', start='2012-01-01', end='2021-04-15')
etc.

With pdr .10 you’ll get

enter image description here

The fix was documented here:
https://pandas-datareader.readthedocs.io/en/latest/whatsnew.html

Bug Fixes

- Fixed Yahoo readers which now require headers

Many thanks to the Pandas team for fixing this so quickly!

Answered By: James_SO
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.