I am creating a stock exchange monitor in python, and have had problems with the pandas_datareader module. The original module in the code was pandas.io.data, but an amendment has been made as pandas no longer supports this module. Here is the code;
import pandas as pd
import pandas_datareader as web
import datetime
start = datetime.datetime(2016, 1, 1)
end = datetime.date.today()
apple = web.DataReader("AAPL", "yahoo", start, end)
type(apple)
This code comes with the error;
Traceback (most recent call last):
File "/Users/euanoflynn/anaconda/tests/Tests.py", line 2, in <module>
import pandas_datareader as web # Package and modules for importing data; this code may change depending on pandas version
ModuleNotFoundError: No module named 'pandas_datareader'
I feel like I'm doing something wrong.
I can post more information if need be.
Have you checked that the module pandas_datareader
is installed? You can verify by running the command pip show pandas_datareader
in a command shell. If it does not return any output, you can install with pip install pandas_datareader
from the command shell as well.
If you want to install the missing package directly in a script, you have to modify your script by adding to your script, after the last import
line:
import pip
pip.main(['install', 'pandas_datareader'])
as indicated in Installing python module within code
I verified that the example works, but you may want to know that some people experience intermittent issues with the price scraping API, as per https://github.com/pydata/pandas-datareader/issues/170