【发布时间】:2020-12-17 06:08:48
【问题描述】:
我有一个大的 Excel 表,我的数据如下所示:
type price
shoes 10
clothes 20
shoes 30
clothes 40
我想将“30”和“40”值移动到新列,稍后我将删除现有行。我希望它会像这样显示:
type price new price
shoes 10 30
clothes 20 40
如何在 python 中实现?
谢谢
【问题讨论】:
-
到目前为止你的代码是什么?
-
df.assign(temp=df.groupby("type").cumcount()).pivot("type", "temp", "price").rename_axis(columns=None, index=None).set_axis(["price", "new_price"], axis="columns")