Pycharm pandas_datareader not found
Asked Answered
C

1

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.

Cyma answered 25/10, 2017 at 1:0 Comment(0)
R
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

Rosmunda answered 25/10, 2017 at 1:51 Comment(3)
This is the result; pip show pandas_datareader File "<ipython-input-2-155e3cc1be26>", line 1 pip show pandas_datareader ^ SyntaxError: invalid syntax1Cyma
And for the other... pip install pandas_datareader File "<ipython-input-3-16663e45080a>", line 1 pip install pandas_datareader ^ SyntaxError: invalid syntaxCyma
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.Rosmunda

© 2022 - 2024 — McMap. All rights reserved.