我正在使用 python 包 yfinance 下载数据,下面是我为此使用的代码:
# pip install yfinance
import yfinance as yf
# list of tickers for which data is to be downloaded
myLst = ['TSLA', 'MSFT', 'FB', 'IBM', 'AAPL', 'WFC', 'BAC', 'INTC', 'PRLAX', 'QASGX', 'HISFX']
# from which date?
start_date = '2018-01-01'
# to which date?
end_date = '2019-12-31'
# download the data
mydf = yf.download(myLst, start = start_date, end = end_date, group_by = "ticker")
这将返回数据框中的数据,如下所示:
但我无法将这些数据放入这样的数据框中:
虽然我尝试过这样的事情:
assets = ['IBM', 'MSFT', 'FB']
assetsDF = pd.DataFrame({
a: {x['Close'] for x in mydf[a]['Close']} for a in assets
})
但我知道我在这里不正确。有什么解决办法吗?