Solve ImmediateDeprecationError Get Yahoo data with Python

Recently, I am looking at the content of data processing with python, and many tutorials will use pandas to capture financial data. I also tried running the example code on the tutorial to grab the data.

This article focuses on the problems encountered and their solutions.

Note: I am using Python 3.6.1

 

1. import pandas.io.data as web

The tutorials I have seen all use the above form to import pandas.io.data, but this method does not support this import form in pandas 0.19.0 and above, and the function of this module has been migrated to pandas-datareader. The pandas version I am using is 0.22.0, which must no longer support pandas.io. The following error will appear when using the old method to reference

import pandas.io.data as web   # Package and modules for importing data; this code may change depending on pandas version
  File "D:\Program Files (x86)\Python\lib\site-packages\pandas\io\data.py", line 2, in <module>
    "The pandas.io.data module is moved to a separate package "
ImportError: The pandas.io.data module is moved to a separate package (pandas-datareader). After installing the pandas-datareader package (https://github.com/pydata/pandas-datareader), you can change the import ``from pandas.io import data, wb`` to ``from pandas_datareader import data, wb``.

So according to the prompt, install the pandas-datareader module

pip install pandas-datareader 

After installation, replace pandas.io with pandas-datareader

import pandas-datareader.data as web  

The problem is solved satisfactorily.

 

2. ImmediateDeprecationError

The second problem soon followed, when I tried to scrape the data source from yahoo using the following code, the second problem appeared.

import pandas as pd
import pandas_datareader.data as web   # Package and modules for importing data; this code may change depending on pandas version
import datetime
 
# We will look at stock prices over the past year, starting at January 1, 2016
start = datetime.datetime(2016,1,1)
end = datetime.date.today()
 
# Let's get Apple stock data; Apple's ticker symbol is AAPL
# First argument is the series we want, second is the source ("yahoo" for Yahoo! Finance), third is the start date, fourth is the end date
apple = web.DataReader("AAPL", "yahoo", start, end)
 
type(apple)

The following error will be reported

raceback (most recent call last):
  File ".\l1.py", line 11, in <module>
    apple = web.DataReader("AAPL", "yahoo", start, end)
  File "D:\Program Files (x86)\Python\lib\site-packages\pandas_datareader\data.py", line 291, in DataReader
    raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Yahoo Daily'))
pandas_datareader.exceptions.ImmediateDeprecationError:
Yahoo Daily has been immediately deprecated due to large breaks in the API without the
introduction of a stable replacement. Pull Requests to re-enable these data
connectors are welcome.

See https://github.com/pydata/pandas-datareader/issues

However, this error, searched a lot of results on the Internet, but could not find a solution. I have no choice but to search for similar questions through the github link below. I saw someone raised this issue on github .

I did get a lot of answers from great gods, but many methods were successful on other people's computers, and I still failed when I tried it myself.

Let me introduce my successful solution directly here:

(1) Roll back the pandas-dataread version to 0.5.0. The default pandas-datareader installed with pip is 0.6.0, roll back the version and try again, and find that the above code can be successfully run;

(2) Install fix_yahoo_finance, which is a patch shared by experts, specifically to solve the method that pandas-datareader cannot obtain yahoo financial data.

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324650710&siteId=291194637