I would like to save the output from the following Python loop to CSV
ticker_list = ['GBX', 'AYI', 'SMPL', 'BSET']
from yahoofinancials import YahooFinancials as yf
yahoo_financials = yf(ticker_list)
price = yahoo_financials.get_historical_price_data('2019-07-02', '2019-07-02', 'daily')
df = pd.DataFrame(price)
def get_price():
df1 = pd.DataFrame()
for i in ticker_list:
df1_i = pd.DataFrame(df[i]['prices'])
df1_i['ticker'] = i
df1 = df1.append(df1_i)
df1.to_csv(r'price_20190702.csv')
I want to save the price info for all four tickers to a single CSV file. However, when I call def get_price(), no CSV file is saved.
df1.to_csv(r'price_20190702.csv')?