I am currently trying to export my data frame into a csv. The basis of the code is to run a list of tickers through yahoo_fin and get options data. The code works, and I retrieve info for every ticker, however, when I assign the stocks a data frame to export into csv form, the csv only opens with the last item on the list. Example:
stocks = ['AAPL', 'AMZN']
for stock in stocks:
try:
pd.set_option('display.max_columns', None)
chain = options.get_options_chain(stock, 'October 15, 2021')
print(chain['calls'])
except:
ValueError
df = pd.DataFrame(chain['calls'], columns=['Contract Name', 'Last Trade Date', 'Strike', 'Last Price', 'Bid', 'Ask', 'Change', 'Volume', 'Implied Volatility'])
df.to_csv(r'C:\Users\etcetc, index= False, header= True)```
#I am new to python and any help is appreciated! I tried running the data through XlsxWriter and it didn't work either.
#Thanks!