[英]Transpose specific rows into columns in pandas
I have a dataset that has information like below:我有一个数据集,其中包含如下信息:
Title Year Revenue (Mi)
---------------------------------------------------------------
Guardians of the Galaxy 2015 313.13
Split 2016 138.0
Sing 2016 270.32
Moana 2015 248.02
I want to convert this piece of data to this form:我想将这段数据转换为这种形式:
Title 2015 2016
------------------------------------------------------------
Guardians of the Galaxy 313.13
Split 138.02
Sing 270.32
Moana 248.02
How can I convert my data frame to this form??如何将我的数据框转换为这种形式? I am not getting what should I do in this case.
在这种情况下,我不知道该怎么做。
Try with尝试
out = df.pivot(index='Title', columns='Year', values='Revenue (Mi)').reset_index()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.