May-25-2018, 03:48 PM
I have a problem about converting raw data into panel data.
I got the following data in excel like:
Name MMMmarketcap MMMstoctprice APPLmarketcap APPLstoctprice ... (i)marketcap (i)stockprice
01/2001 a1 b1 c1 d1
.... ... ... ... ...
05/2018 an bn ... ...
How can I convert the data into panel format like:
Date Name MarketCap Stock Price
01/2001 MMM a1 b1
....
05/2018
01/2001 AAPL c1 d1
....
05/2018
I try but i cannot get the result expected :
Name Variable Value
01/2001 MMMmarketcap a1
....
05/2018 MMMmarketcap an
01/2011 MMMstockprice b1
....
05/2018 MMM stockprice bn
Many thanks for helping.
I got the following data in excel like:
Name MMMmarketcap MMMstoctprice APPLmarketcap APPLstoctprice ... (i)marketcap (i)stockprice
01/2001 a1 b1 c1 d1
.... ... ... ... ...
05/2018 an bn ... ...
How can I convert the data into panel format like:
Date Name MarketCap Stock Price
01/2001 MMM a1 b1
....
05/2018
01/2001 AAPL c1 d1
....
05/2018
I try but i cannot get the result expected :
df1 = pd.melt(df,id_vars=["Name"])I got something like:
Name Variable Value
01/2001 MMMmarketcap a1
....
05/2018 MMMmarketcap an
01/2011 MMMstockprice b1
....
05/2018 MMM stockprice bn
Many thanks for helping.