Data analysis to obtain Yahoo stock data: some problems are encountered when using panda datareader (cannot import name ‘is_ list_ Like ‘problem)

1. Install the Quilt-Datareader dependency package:
Because Python 3.6 was already installed on my computer and I had learned about crawlers first, I already had a Python environment. Now I learn data scientific data analysis and install Anaconda again. In order not to cause chaos in my computer environment, after installing Anaconda, the environment variable of Anaconda is not written into the system environment variable. Then, to install the third party and use imperative operation, I need to open CMD in the path of the installation directory:
1.1 Use anaconda’s Python environment
In the root directory of the Anaconda installation, open CMD, enter Python, and this is the Python environment where the Anaconda is executed.
1.2 Use the conda command to install dependency packages or to view dependencies and other commands to be executed by Conda
Use the conda command: go to Anaconda3- > Library -> Execute under bin path (open CMD)
Open CMD in the directory above and execute conda commands, such as conda Install Augmentation-Datareader, etc
Check the anaconda in the environment depend on the package: conda list;
2 use the pandas – the datareader
Error importing pandas_datareader: cannot import name ‘is_list_like’
With this in mind, we can look at the reasons for the import error:

It says a file called Fred.py. We still don’t know what causes it. Look for the solution on the Internet and find an effective way to modify a statement of the file:
The first line of the original Fred.py file into the opening import is this from pandas.core.common import is_list_like
We modify this sentence to: from Safari. API. Types import is_list_like
When you go back to import, you find that the import was successful.
2.2 Use pandas_datareader to get Yahoo stock data and find an error.
pandas_datareader.get_data_yahoo(‘BABA’)

The reason has been stated in the content. This API interface has been abandoned. After checking the data, I found that it may be the reason why Yahoo was acquired by Verizon in 2017.
But there’s a new solution online:
We need to install an additional dependency package: fix_yahoo_finance (conda install again)
Import FIX_yahoo_Finance as fy after successful installation
From pandas_datareader import data as PDR

import fix_yahoo_finance as yf
yf.pdr_override() # needs to call this function

# to get data
data = PDR get_data_yahoo(“SPY”, start=”2017-01-01″, end=”2017-04-30″)
data = pdr.get_data_yahoo([“SPY”, “IWM”], start=”2017-01-01″, end=”2017-04-30″)
Tips: On Conda Install fix_yahoo_Finance, you may run into PackageNotFoundError: “Package missing in current channels”.
Solution 1:
Find the dependencies you want to install
Anaconda Search-t Conda you want to install packages such as Yahoo
(If there is no Python variable with anaconda added in the environment variable, it will be executed under the scripts installed)

As shown in the figure, you can see the installation package found (the result of the fuzzy search), but of course this package may not be searched, such as the one at the beginning (the unboxed part at the top).
If you do, you’ll see anaconda show < USER/PACKAGE> This is used to further view the installation information you want to install.
For example, I select one to view
anaconda show postelrich/yahoo-finance

The package will be given some information in the front, the last will be given how to install the directory, copy it, in conda is ok:
Conda install yahoo – channel https://conda.anaconda.org/postelrich – finance
Solution 2: Install locally
What do you do if you can’t find the dependencies you want to install?Download the file and install it locally.
For example, I used to use AlphaGam-DatareadErr to obtain stock data from Yahoo’s interface when I acquired the stock, but unfortunately I cannot do so now. The interface has been removed.
A search on the Internet found a FIX_yahoo_finance package can achieve the previous operation, so immediately go to conda Fix_yahoo_finance, found that the installation cannot, anaconde Search can not find this package, so I went to fix_yahoo_finance API website to find the source file download address, download to the local.
Documents: https://pypi.org/project/fix-yahoo-finance/
Download Address:
https://files.pythonhosted.org/packages/0a/96/d44330e427f5368cb8abd25997b72956a31b52073d285c4d5cd56e5fdc17/fix-yahoo-finance-0.0.22.tar.gz
Depending on the package, download and unzip the file setup.py

We can install this package locally. How to install it
CD into the fix_yahoo_finance directory, install it with Python setup.py install, and it will automatically install the dependency into the environment.
Don’t be fooled by my Pythonana, this is because I have two Pythons installed on my computer at the same time, as Mentioned earlier, so I’ve changed one python command to Python so that my Python doesn’t get in a fight. If you haven’t changed it, you can ignore it, and just go ahead and install it in Python.

At this point, we use:
From pandas_datareader import data as PDR

import fix_yahoo_finance as yf
yf.pdr_override() # needs to call this function

# to get data
data = PDR get_data_yahoo(“SPY”, start=”2017-01-01″, end=”2017-04-30″)
data = pdr.get_data_yahoo([“SPY”, “IWM”], start=”2017-01-01″, end=”2017-04-30″)
The stock data in Yahoo can be obtained normally, and the request network to obtain data is also relatively stable.

Read More: