1

I have a data frame with the following shape:

Index  Col1 Col2 Col3  
 1      A    B    C
 2      D    E    F
 3      G    H    I

I would like to receive a data frame with the following shape:

1 Col1 A
1 Col2 B
1 Col3 C
2 Col1 D
2 Col2 E
...

Already went through .groupby(), pivot(), iterators but no success

Ilya
  • 23
  • 3

1 Answers1

0

I think you need,

df.melt()

O/P:

    variable    value
0   Col1    A
1   Col1    D
2   Col1    G
3   Col2    B
4   Col2    E
5   Col2    H
6   Col3    C
7   Col3    F
8   Col3    I
Mohamed Thasin ah
  • 10,754
  • 11
  • 52
  • 111