In my case, I have an empty dictionary which I want to fill with Key:Value pairs about stock tickers information. I tested the code below but I always get a KeyError message whenever a key is missing from the list of tickers I loop through. All I want is to set a group of default Keys for all my tickers (Info_data in the code below), then set the value of the missing "Key" to "None" whenever it finds a missing key.
Here is my code:
stocks_info = {}
for symbol in tqdm(sav_set):
info = yf.Tickers(symbol).tickers[symbol].info
if info['quoteType'] == 'EQUITY':
info_data = {'symbol': symbol, 'shortName': info['shortName'], 'country': info['country'],
'sector': info['sector'], 'industry': info['industry'], 'marketCap': info['marketCap'],
'currentPrice': info['currentPrice'], 'quoteType': info['quoteType'], 'market': info['market']}