for example, dataframe is below
A B
a 1 2
b 3 4
I want to put column to index
the result i want is below
value
a A 1
a B 2
b A 3
b B 4
how can i get the result?
>Solution :
You can do a dataframe melt, and then turn the variable column into an index column
pd.melt(df, value_vars=['A','B'], var_name='', ignore_index=False).set_index('',append=True)