2

I am new to python. I have a dataframe in below format

enter image description here

I want to pivot it to below format

enter image description here

How can i do this?

Nishant Gupta
  • 3,533
  • 1
  • 11
  • 18
  • 1
    Does this answer your question? [pandas convert some columns into rows](https://stackoverflow.com/questions/28654047/pandas-convert-some-columns-into-rows) – ThePyGuy Aug 27 '21 at 05:33
  • 1
    What you are showing is not *Pivot*, its called **melt** in pandas – ThePyGuy Aug 27 '21 at 05:36

1 Answers1

1

Try using df.melt:

print(df.melt(id_vars='Name'))

If pandas version is under 0.20.0, try pd.melt:

print(pd.melt(df, id_vars='Name'))
U13-Forward
  • 69,221
  • 14
  • 89
  • 114