Pivot a dataframe

Viewed 41

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?

1 Answers

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'))
Related