I'm new to python and I'm trying to retrieve stock data using a for loop and then save that information as a dataframe to then save as .csv. Basically, I'm creating a custom_stock_data function that will pass the ticker_list (containing the stock symbols). I then want each item on this list to be passed through the for loop so that the data can be saved as a dataframe in the variable ticker_data and save it as .csv. I then do ticker_data += 1 to move to the next csv file (I don't know if this is how you can do it, any help is welcome!)
This is the code:
def custom_stock_data (ticker):
ticker_data = []
for symbol in ticker:
ticker_data = pd.DataFrame(get_data(symbol, start_date = "05/25/2021", end_date = "07/30/2021", interval = "1wk"))
ticker_data.to_csv(r"C:\xampp\htdocs\estagio\data_{}.csv".format(symbol))
ticker_data += 1
print(ticker_data)
ticker_list = ["AMZN", "TSLA", "AAPL"]
custom_stock_data(ticker_list)
I am also only getting the last information on my ticker_list (which would be AAPL). I can't seem to be getting the information on the first two tickers, as shown in the picture
Thank you!
