1

I am trying to unpivot this below dataframe.

My dataframe:

enter image description here

Output

enter image description here

yatu
  • 86,083
  • 12
  • 84
  • 139
Shankar Panda
  • 736
  • 3
  • 11
  • 27

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
  • 86,083
  • 12
  • 84
  • 139