So I have the following code as an exercise and I am trying to melt and unmelt the table using pivot. These are what I have so far:
sp500data=yf.Tickers('MMM ABT ...ZTS).history(group_by='ticker',period = '2y')
melted = sp500data.reset_index().melt(id_vars=['Date'], value_name='Value').rename(columns={'variable_0':'Ticker','variable_1':'Attributes' })
pivoted = melted.pivot(index='Date', columns='Attributes')
I get error whenever I try to display pivoted('ValueError: Index contains duplicate entries, cannot reshape')
. Please help