I am downloading data using python package yfinance and below is the code I am using for this:
# 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")
This returns me the data in a dataframe which looks like this:
But I am not able to get this data into a dataframe like this:
Although I tried something like this :
assets = ['IBM', 'MSFT', 'FB']
assetsDF = pd.DataFrame({
a: {x['Close'] for x in mydf[a]['Close']} for a in assets
})
But I know I am not correct here. Is there any solution?