我有一個很大的 Excel 工作表,我的數據如下所示:type priceshoes 10 clothes 20shoes 30clothes 40我想將“30”和“40”值移動到新列,稍后我將刪除現有行。我希望它會像這樣顯示:type price new priceshoes 10 30clothes 20 40我怎樣才能在Python中做到這一點?
1 回答

慕森王
TA貢獻1777條經驗 獲得超3個贊
你可以試試這個:
df['newprice'] = df.groupby('type')['price'].transform('max')
df = df.drop_duplicates(subset="type", keep="first")
print(df)
輸出:
type price newprice
0 shoes 10 30
1 clothes 20 40
添加回答
舉報
0/150
提交
取消