I get KeyError: "['marketCap'] not in index" when there is no data in the "marketCap" column for a particular symbol. How do I put "Null" when there's no data so the code can continue running and not error out?
import pandas as pd
from yahooquery import Ticker
symbols = ['MSFT','GOOG','AAPL'] #I have to put 75,000+ symbols here.
header = ["regularMarketPrice", "marketCap"]
for tick in symbols:
faang = Ticker(tick)
faang.price
df = pd.DataFrame(faang.price).T
df.to_csv('output.csv', mode='a', index=True, header=False, columns=header)