Last answered:

18 May 2023

Posted on:

13 May 2023

0

Pandas_DataReader Error Message. The code that generated the error message is at the bottom



---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[5], line 5
      2 pf_data = pd.DataFrame()
      4 for a in assets:
----> 5     temp_data = wb.DataReader(a, data_source='yahoo', start='2010-01-01')
      6     pf_data[a] = temp_data['Adj Close']

File ~\anaconda3\Anaconda23\lib\site-packages\pandas\util\_decorators.py:211, in deprecate_kwarg.<locals>._deprecate_kwarg.<locals>.wrapper(*args, **kwargs)
    209     else:
    210         kwargs[new_arg_name] = new_arg_value
--> 211 return func(*args, **kwargs)

File ~\anaconda3\Anaconda23\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 ~\anaconda3\Anaconda23\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 ~\anaconda3\Anaconda23\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

assets = ['PG' , '^GSPC']
pf_data = pd.DataFrame()

for a in assets:
    temp_data = wb.DataReader(a, data_source='yahoo', start='2010-01-01')
    pf_data[a] = temp_data['Adj Close']
1 answers ( 0 marked as helpful)
Instructor
Posted on:

18 May 2023

0

Hi Ernest!
Thanks for reaching out.


Yahoo have recently made changes to their API so currently the code provided is unable to provide the dataset as shown in the video lectures. Potentially, this will only be a temporary issue (as have happened in the past), meaning that once Yahoo fix the related issues themselves, the code will start working again.
Of course, this depends entirely on their data teams, so we cannot guarantee the future outcome of these changes with certainty. Therefore, to ensure you smooth continuation with taking this course, please consider applying one of the following options (suggestions provided in order of preference according to us):
- use the *.csv files we've provided to the lectures
- use yfinance instead of pandas-datareader
- use pycryptodome or pycryptodomex (risking to use data that is not as reliable as of now)


Hope this helps.
Kind regards,
The 365 Team

Submit an answer