Last answered:

25 Mar 2023

Posted on:

22 Mar 2023

0

An error is occuring when we execute PG = wb.DataReader('PG', data_source='yahoo', start='1995-1-1')

Tried following:

pip install --upgrade pandas
pip install --upgrade pandas-datareader

Still getting error.

Error Details: 

~\anaconda3\lib\site-packages\pandas_datareader\base.py in 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):

~\anaconda3\lib\site-packages\pandas_datareader\yahoo\daily.py in _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

2 answers ( 0 marked as helpful)
Posted on:

22 Mar 2023

0

Found following solution:

import pandas
from pandas_datareader import data as pdr
import yfinance as yfin
yfin.pdr_override()

df = pdr.get_data_yahoo("PG", start="1995-1-1", end="2023-1-1")
print(df)

Posted on:

25 Mar 2023

0

Hi Alok!


Thanks for reaching out.


Thank you for sharing your solution with the Community and letting us know you are able to continue taking the course.

Indeed, yfinance is a good alternative we have not switched to yet, mainly because of the low reliability of such modules/APIs we've been observing during the past few years. Although yfinance, in particular, has been quite stable itself. 

That's why we'd still advise you to use the *.csv files provided to complete the course and only when you've finished it, then, so to say, "experiment" with various modules for obtaining data online.


Hope this helps.
Best,
Martin

Submit an answer