Resolved: 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
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)
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
hello mr. Martin,
i wanna to ask you why yfinance doesn't work with me.
also i can't add kernel python2, i working only with python3
so please answer to me asap
thank you
Thanks Alok. Your solution worked for me
Hi Amal and Mayurkumar!
Thanks for reaching out.
@Amal: If you are currently working with Python 3, I don't think you should be worried - it's better to work with Python 3 than 2, so your kernel should be sufficient.
Regarding yfinance - have you installed that module first?
Hope this helps.
Kind regards,
Martin