5

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.

spac
  • 346
  • 1
  • 10
Elesh Norn
  • 165
  • 1
  • 8

1 Answers1

8

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

spac
  • 346
  • 1
  • 10
  • This is the result; `pip show pandas_datareader File "", line 1 pip show pandas_datareader ^ SyntaxError: invalid syntax1` – Elesh Norn Oct 27 '17 at 03:22
  • And for the other... `pip install pandas_datareader File "", line 1 pip install pandas_datareader ^ SyntaxError: invalid syntax` – Elesh Norn Oct 27 '17 at 03:26
  • you have to run those commands in a shell, not in the python interpreter. If you want to can install from within the interpreter using the pip module. I will edit my answer to include this option. – spac Oct 27 '17 at 19:55