6

I want to print out SPY's stock data however it keeps shows typeerror: string indices must be integer

import pandas_datareader.data as web

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

print(spy)
umklapper
  • 105
  • 1
  • 1
  • 5
  • 1
    web.get_data_yahoo('SPY', start='2022-10-24', end='2022-12-23') – tomerar Dec 25 '22 at 09:26
  • This was already asked here [why am I getting a "TypeError: String indices Must be integer" Message when trying to access Yahoo Finance?](https://stackoverflow.com/q/74862453/6045800) and it seems to be [a known issue](https://github.com/pydata/pandas-datareader/issues/952) – Tomerikoo Dec 25 '22 at 09:32
  • @tomerar thank you! but it says the start date can't be earlier than the end date – umklapper Dec 25 '22 at 09:43
  • Swap "start" and "end". – TradingDerivatives.eu Dec 31 '22 at 13:18
  • 1
    Does this answer your question? ["TypeError: string indices must be integers" when getting data of a stock from Yahoo Finance using Pandas Datareader](https://stackoverflow.com/questions/74832296/typeerror-string-indices-must-be-integers-when-getting-data-of-a-stock-from-y) – crypdick Jan 26 '23 at 15:42

1 Answers1

17

I would solve for this way:

import pandas
from pandas_datareader import data as pdr
import yfinance as yfin


yfin.pdr_override()

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

print(spy)

I think it will work.

StasNemy
  • 142
  • 2
  • 4
Lucas Lima
  • 171
  • 1
  • 4