Yfinance Indexerror: List Index Out Of Range
I wrote the code below and it is running. When the loop run a fourth time, it gives an error. It gives 'IndexError: list index out of range'. How do I fix this error? import yfinan
Solution 1:
- For 8 of the tickers, the
yfinance.ticker.Ticker
object,stk_container.info
results in an error when there is only 1 holder. This is a bug. - yfinance: Index out of range: some Tickers #208
- Use a
try-except
block to catch the exception. - You may fix the
yfinance
codebase with YFinance - tickerData.info not working for some stocks
import yfinance as yf
dow_list = ['AAPL', 'AXP', 'BA', 'CAT', 'CSCO', 'CVX', 'DIS', 'DOW', 'GS', 'HD', 'IBM', 'INTC', 'JNJ', 'JPM', 'KO', 'MCD', 'MMM', 'MRK', 'MSFT', 'NKE', 'PFE', 'PG', 'RTX', 'TRV', 'UNH', 'V', 'VZ', 'WBA', 'WMT', 'XOM']
rows = []
for ticker in dow_list:
stk_container = yf.Ticker(ticker)
try:
stk_info = stk_container.info
print(stk_info) # print the info
except IndexError as e:
print(f'{ticker}: {e}') # print the ticker and the error
print('\n')
Post a Comment for "Yfinance Indexerror: List Index Out Of Range"