根据多列非重复计数熊猫创建一列

时间:2018-11-22 08:06:52

标签: python pandas

我有一个df

Family  Product     Date    Price
A           1   7/17/2017    3
B           3   2/5/2018     5
A           1   7/17/2017    4
A           1   7/17/2017    4
B           3   2/5/2018     5

我希望我的输出看起来像

Family  Product     Date    Price Count
A           1   7/17/2017    3      2
B           3   2/5/2018     5      1
A           1   7/17/2017    4      2
A           1   7/17/2017    4      2
B           3   2/5/2018     5      1

我正在尝试获得所需输出的代码(每三列的价格不同)

df['Count']=df.groupby(['Family','Product','Date'])['Price'].nunique()

,我得到的错误是“ TypeError:插入的列与框架索引的索引不兼容”。我希望有人可以帮助我

0 个答案:

没有答案
相关问题