I\'ve seen similar questions but mine is more direct and abstract.
I have a dataframe with \"n\" rows, being \"n\" a small number.We can assume the index is just the
Let's try this, using stack, to_frame, and T:
stack
to_frame
df.index = df.index + 1 df_out = df.stack() df_out.index = df_out.index.map('{0[1]}_{0[0]}'.format) df_out.to_frame().T
Output:
A_1 B_1 C_1 D_1 E_1 A_2 B_2 C_2 D_2 E_2 A_3 B_3 C_3 D_3 E_3 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 5