Shravan Kolya
Shravan Kolya

Reputation: 23

Pivot a dataframe

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?

Upvotes: 2

Views: 51

Answers (1)

U13-Forward
U13-Forward

Reputation: 71580

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

Upvotes: 1

Related Questions