How to turn: Original dataframe
into this: Wanted dataframe
(sorry I don't know how to paste excel table here.)
Been messing around with pandas stack, pivot_table, melt, but can't seem to make it work. I need some ideas. Thanks.
I created excel for the shown screenshot of the sheetfile
df = pd.read_excel('PythonExport.xlsx',
header=[0,1,2],index_col=[0,1],
)
df:
x = df.T.swaplevel(0,1).T.stack().stack().reset_index()
x.columns = ['repeat','condition','day','type','length','weight']
x = x.fillna(0)
x:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.