make a dataframe base on a rows and columns of another dataframe

i have a a dataframe ‘a’ like this:

A header c1 c2 c3 c4 c5
c1 0 1 3 4 2
c2 2 4 3 2 4
c3 2 4 1 2 2
c4 8 4 6 5 7
c5 7 4 5 8 9

now, i want to make a dataframe based on previous dataframe with name ‘b’.

column1 column2 column3
c1 c1 0
c1 c2 1
c1 c3 3
c1 c4 4
c1 c5 2
c2 c1 2
c2 c2 4
c2 c3 3
c2 c4 2
c2 c5 4
c3 c1 2
c3 c2 4
c3 c3 1
c3 c4 2
c3 c5 2
c4 c1 8
c4 c2 4
c4 c3 6
c4 c4 5
c4 c5 7
c5 c1 7
c5 c2 4
c5 c3 5
c5 c4 8
c5 c5 9

could you help me to make this second dataframe ?
thanks

>Solution :

You can try this:

a.stack().reset_index()

Leave a Reply