我在df.to_csv
行上得了KeyError: "['CashFinancial'] not in index"
分,因为‘GOOG’没有CashFinancial
列.我怎么能让它在null
中写下‘GOOG’的CashFinancial
值呢?
import pandas as pd
from yahooquery import Ticker
symbols = ['AAPL','GOOG','MSFT'] #This will be 75,000 symbols.
header = ["asOfDate","CashAndCashEquivalents","CashFinancial","CurrentAssets","TangibleBookValue","CurrentLiabilities","TotalLiabilitiesNetMinorityInterest"]
for tick in symbols:
faang = Ticker(tick)
faang.balance_sheet(frequency='q')
df = faang.balance_sheet(frequency='q')
df.to_csv('output.csv', mode='a', index=True, header=False, columns=header)