1

I am trying to unpivot this below dataframe.

My dataframe:

enter image description here

Output

enter image description here

yatu
  • 80,714
  • 11
  • 64
  • 111
Shankar Panda
  • 682
  • 3
  • 10
  • 25

1 Answers1

3

You're looking for pd.melt:

df.melt(id_vars=['id', 'col1', 'col2'])

   id col1 col2 variable  value
0   1    a    e     val1      3
1   1    a    e     val2      7
yatu
  • 80,714
  • 11
  • 64
  • 111