I have a dataset that has information like below:
JavaScript
x
7
1
Title Year Revenue (Mi)
2
---------------------------------------------------------------
3
Guardians of the Galaxy 2015 313.13
4
Split 2016 138.0
5
Sing 2016 270.32
6
Moana 2015 248.02
7
I want to convert this piece of data to this form:
JavaScript
1
7
1
Title 2015 2016
2
------------------------------------------------------------
3
Guardians of the Galaxy 313.13
4
Split 138.02
5
Sing 270.32
6
Moana 248.02
7
How can I convert my data frame to this form ?? I am not getting what should I do in this case.
Advertisement
Answer
Try with
JavaScript
1
2
1
out = df.pivot(index='Title', columns='Year', values='Revenue (Mi)').reset_index()
2