I’m fairly new to Python so bare with me. I am attempting to select 5 different stocks in this command
the stocks I chose in the portfolio
stocks = [‘AMZN’,‘MSFT’,‘PFE’, ‘BA’, ‘JPM’]
names=[‘AMAZON’,‘MICROSOFT’,‘PFIZER’,‘BOEING’,‘JPMORGAN’]
#get the stock data from Yahoo Finance
df = web.DataReader(stocks,data_source=‘yahoo’,start=start_date,end=end_date)
The problem arises when I use this command following it:
#create a new dataframe
#we want to use additional features: lagged returns…today’s returns, yesterday’s returns etc
tslag = pd.DataFrame(index=df.index)
tslag[“Today”] = df[“Adj Close”]
The last line shows up with an error saying: ValueError: Wrong number of items passed 5, placement implies 1
But when I replace stocks in the initial one above (df) and instead put a stock ticker such as ‘amzn’, then I am fine. But it only works if I use one. I can’t even use two. Can someone help me understand the issue here? Thanks