I have created the following dataframe called df
col1 col2 col3
0 4 5 2
1 5 2 4
2 3 10 3
3 6 2 2
4 3 2 4
What I would like now is to flip the rows so that the df looks like this:
column_name value
0 col1 4
1 col2 5
2 col3 2
3 col1 5
4 col2 2
5 col3 4
... ... ...
I think I need to use stack(), but I'm not sure how. I've tried the following
df = df.stack().rename_axis(['column_name']).reset_index(name = 'value')
but that returns the following error
raise ValueError('Length of names must match number of levels in '
ValueError: Length of names must match number of levels in MultiIndex.
Question: how do I stack the values so that I get the desired dataframe?