-1

I'm using pandas data reader package to pull stock price data from Yahoo. The application works and I've used it many times in the past. Now it has stopped working. When I try to pull the data I get a type error about how string indices must be integers. Is this problem happening to anyone else?

I'm not really sure what else I can do except to change a data source. Is this a problem with my end or with Pandas and Yahoo?

  • This is a duplicate - search with `python Pandas Datareader no longer working with Yahoo finance site:stackoverflow.com` - limit the search to the last week or two. It's also *off-topic* for SO. – wwii Dec 22 '22 at 03:46
  • Please provide enough code so others can better understand or reproduce the problem. – Community Dec 22 '22 at 11:03
  • The following solution worked for me: [link](https://stackoverflow.com/questions/74862453/why-am-i-getting-a-typeerror-string-indices-must-be-integer-message-when-tryi). You may find a better explanation of what might have happened (and more complicated solutions) here: [link](https://stackoverflow.com/questions/74832296/typeerror-string-indices-must-be-integers-when-getting-data-of-a-stock-from-y) – Allan Jan 08 '23 at 12:46

2 Answers2

0
tickers = ['DOW', 'XOM', 'IBM', 'VZ', 'CVX', 'PFE', 'MMM', 'WBA', 'CSCO', 'KO']
tickers = sorted(tickers)
shares = np.array((100, 50, 90, 40, 90, 30, 120, 80, 80, 80))
mydata = pd.DataFrame()
for t in tickers:
   mydata[t] = dr.DataReader(t, 'yahoo', start="2022-12-01")['Close']

This is the code I've been using for a long time, and it suddenly stopped working. I get a TypeError: string indices mush be integers

Bill
  • 15
  • 4
0

Yes, unfortunately I ran into the same issue. I believe the issue is that Yahoo has updated the format of their website...

Thankfully you can fix the issue with two simple lines of code!!

Simply add import yfinance as yf to the top of your code.

Then add yf.pdr_override() to the start of your main function.

This has fixed my issue, I hope it fixes yours too, have a lovely day.

Documentation