Issues with selecting stock

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’]

#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

I’m not a pandas expert, but googling for the error message reveals that this is a common question on Stackoverflow:

As far as pandas is concerned, you are trying to put five columns worth of data into one column.

Unfortunately it looks like every case is unique and needs to be solved differently.

Pandas experts may have some more comments to make, but they will probably want to see the complete error message, starting with the line “Traceback”, copied and pasted as text not as a screenshot.

1 Like