I am trying to convert a dataframe
of structure:
ID ID2 ID3 R_u L_u R_sd L_sd
1 F G1 x y z t
2 M G2 x y z t
into
ID ID2 ID3 Side u sd
1 F G1 R x z
1 F G1 L y t
2 M G2 R x z
2 M G2 L y t
I used pandas.melt
function
df_melt = df(id_vars=[('ID')], value_vars=['R_u', 'L_u'],
var_name='Side', value_name = 'u')
but I couldn't find a way for more than four or six number of columns simultaneously. I guess I can start with melt and then feed each row using lambda
but I feel like I can do this automatically.
Any possible solution, please?