I would like to ask you on how to transpose the dataframe in pandas?
Here is the code:
df = pd.DataFrame([[[1, 2, 3]], [[4, 5, 6]]], index=['step1', 'step2'], columns=['process'])
df
process
step1 [1, 2, 3]
step2 [4, 5, 6]
df1 = df['process'].apply(pd.Series).rename(columns=lambda x: f'sp {x+1}')
df1
sp 1 sp 2 sp 3
step1 1 2 3
step2 4 5 6
out = pd.concat([df1], keys=['process'], axis=1)
out
process
sp 1 sp 2 sp 3
step1 1 2 3
step2 4 5 6
How to transpose the dataframe from (step x sample) becomes (sample x step) like this?
process
step1 step2
sp 1 1 4
sp 2 2 5
sp 3 3 6
Thank you in advance.