我正在尝试从以下位置转换熊猫数据帧:
ID ID_ver type count price discount
1 1 a 4 100 20
1 1 b 3 50 0
1 2 a 4 100 30
1 2 b 3 50 5
1 2 c 1 70 10
自:
ID ID_ver count_a price_a discount_a count_b price_b discount_b count_c price_c discount_c
我有10种不同的可能类型和数千个ID,每个版本最多有10个版本。
我试过了:
df.drop_duplicates()
df.set_index(['ID','ID_VER','TYPE'])[['count','PRICE','DISCOUNT']].unstack()
但得到错误:
索引包含重复的条目,无法改变形状。
尽管我尝试了很多,但不明白为什么。
感谢您的帮助!
猛跑小猪
holdtom
相关分类