Problem with datareader

Hello everyone,

I have the following problem. Can anyone help, please?

When I mport the following libraries:

import math
import pandas_datareader as web
#from pandas_datareader import *
import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential
from keras.layers import Dense, LSTM
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')

I get the following error:

AttributeError             Traceback (most recent call last)
Cell In[31], line 1
----> 1 df = web.Datareader('AAPL', data_source='yahoo',start='2012-01-01', end='2019-12-17')
      3 #df

AttributeError: module 'pandas_datareader' has no attribute 'Datareader'

Please help. I have spent hours searching. I have tried to update pandas through conda and pip but firstly I cant write to Program Data and secondly throuh pip all requirements are already satisfied.

I feel like you haven’t been searching for hours. a quick google search gave me this:

import pandas_datareader.data as pdr
import pandas as pd
import datetime
start = datetime.datetime(2020,1,1)
end = datetime.datetime(2020,4,17)
pfizer = pdr.DataReader("PFE","yahoo",start,end)
pfizer.head()

it seems that Datareader is part of pandas_datareader.data instead of simply pandas.datareader

1 Like

Hi. Thanks. now I get a different error module ‘pandas_datareader.data’ has no attribute ‘Datareader’. Please Thanks. (Is it a problem with jupyter or Anaconda)

Hello. every one. I changed the code to the following:

import math
from pandas_datareader import data
#from pandas_datareader import *
import pandas_datareader.data as pdr
import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential
from keras.layers import Dense, LSTM
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')

import datetime

start = datetime.datetime(2020,1,1)
end = datetime.datetime(2020,4,17)
#pfizer = pdr.DataReader("PFE","yahoo",start,end)
#pfizer.head()
aapl = data.DataReader("AAPL",data_source='yahoo',start='2015-1-1', end='2015-12-31')['Adj Close']

Now I get the following error:

------------------------------------------------------------
TypeError                  Traceback (most recent call last)
Cell In[51], line 19
     16 end = datetime.datetime(2020,4,17)
     17 #pfizer = pdr.DataReader("PFE","yahoo",start,end)
     18 #pfizer.head()
---> 19 aapl = data.DataReader("AAPL",data_source='yahoo',start='2015-1-1', end='2015-12-31')['Adj Close']

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\util\_decorators.py:210, in deprecate_kwarg.<locals>._deprecate_kwarg.<locals>.wrapper(*args, **kwargs)
    208         raise TypeError(msg)
    209     kwargs[new_arg_name] = new_arg_value
--> 210 return func(*args, **kwargs)

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas_datareader\data.py:379, in DataReader(name, data_source, start, end, retry_count, pause, session, api_key)
    367     raise NotImplementedError(msg)
    369 if data_source == "yahoo":
    370     return YahooDailyReader(
    371         symbols=name,
    372         start=start,
    373         end=end,
    374         adjust_price=False,
    375         chunksize=25,
    376         retry_count=retry_count,
    377         pause=pause,
    378         session=session,
--> 379     ).read()
    381 elif data_source == "iex":
    382     return IEXDailyReader(
    383         symbols=name,
    384         start=start,
   (...)
    390         session=session,
    391     ).read()

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas_datareader\base.py:253, in _DailyBaseReader.read(self)
    251 # If a single symbol, (e.g., 'GOOG')
    252 if isinstance(self.symbols, (string_types, int)):
--> 253     df = self._read_one_data(self.url, params=self._get_params(self.symbols))
    254 # Or multiple symbols, (e.g., ['GOOG', 'AAPL', 'MSFT'])
    255 elif isinstance(self.symbols, DataFrame):

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas_datareader\yahoo\daily.py:153, in YahooDailyReader._read_one_data(self, url, params)
    151 try:
    152     j = json.loads(re.search(ptrn, resp.text, re.DOTALL).group(1))
--> 153     data = j["context"]["dispatcher"]["stores"]["HistoricalPriceStore"]
    154 except KeyError:
    155     msg = "No data fetched for symbol {} using {}"

TypeError: string indices must be integers

I highly suggest you learn the basics of python before making such a program.

2 Likes

Hi. I think I solved it.

import math
from pandas_datareader import data
#from pandas_datareader import *
#import pandas_datareader.data as pdr
import numpy as np
import pandas as pd

from pandas_datareader import data as pdr
import yfinance as yfin

from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential
from keras.layers import Dense, LSTM
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')

import datetime

#start = datetime.datetime(2020,1,1)
#end = datetime.datetime(2020,4,17)
#pfizer = pdr.DataReader("PFE","yahoo",start,end)
#pfizer.head()
#aapl = data.DataReader("AAPL",data_source='yahoo',start='2015-1-1', end='2015-12-31')['Adj Close']
yfin.pdr_override()

spy = pdr.get_data_yahoo('SPY', start='2022-10-24', end='2022-12-23')

print(spy)

Thanks so much Jay and Jef and everyone.

1 Like

Hi. You are abolutely right. But what would you suggest. I have gone through all the basic stuff in Corey Scafer’s youtube playlist. But I am not there. Please help. Please suggest what I should learn from. I am weak on Numpy and Python basics. Can you please suggest a good book or youtube playlist or portal or couse. I know it will take time but belive me I am not trying to rush things. I just want to get a really good grip on things. I just wanted to see an AI or Machine Learning program in action first before continuing. Thanks a lot for your help.

Corey Schafer’s video is a great start, but you need to get the basics down a bit more. Some topics I can recommend would be imports, classes, and the library structure in general. https://realpython.com is a great resource, It teaches a variety of topics through projects. One thing to watch out for is you need to understand how your code works while following tutorials, and not just copying code. Ask yourself what you don’t understand, and go search it up on google or read the library’s documentation. When you get an error, make sure you know why you got it and not just copy-paste an answer from online and see that it works. You can also join the python discord, as it is very active and has a ton of people to help you, including professionals in the industry: Python

1 Like

Thankyou so much.

Maybe this is now fixed, but Python is case sensitive. “DataReader” has
a capital “R”.

1 Like

The function name was misspelled as Datareader instead of DataReader