Skip to content Skip to sidebar Skip to footer

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:

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"