Jun-12-2023, 09:49 PM
Hi, I'm picturing a script that will include in a loop everything after the setting of "today" and before the "print" prototyped in the code below. The loop will read symbols from a notepad file line by line. I would substitute the hardcoded Ticker settings you see below with the symbol just read from notepad. If the record read is the first, the download call where AAPL is now a placeholder would be called. Otherwise the placeholder for the WMT call would be executed.
The download method allows passing multiple tickers in a call but long term I think this will be more flexible. From what I can tell, if you don't pass multiple symbols in a call, you don't get a column for Ticker.
Can I make this more elegant? It seems awkward.
The download method allows passing multiple tickers in a call but long term I think this will be more flexible. From what I can tell, if you don't pass multiple symbols in a call, you don't get a column for Ticker.
Can I make this more elegant? It seems awkward.
import yfinance as yf import pandas as pd from datetime import date today = date.today() Ticker="AAPL" data1 = yf.download(Ticker, start="2023-05-01", end=today).round(2) data1["Ticker"]=Ticker Ticker="WMT" data2 = yf.download(Ticker, start="2023-05-01", end=today).round(2) data2["Ticker"]=Ticker data1=[data1,data2] data1 = pd.concat(data1) print(data1)