我在Pandas中有以下数据集DataFrame。
InvoiceId StockCode Price
XXX ProductA 199,00
XXX ProductB 78,00
XXX ProductC 100,00
YYY ProductB 78,00
YYY ProductA 199,00
ZZZ ProductA 199,00
ZZZ ProductB 78,00
... ... ...
ZZZ ProductY 19,00
我想计算每件产品的购买频率,并将我的产品排在前列DataFrame。我怎样才能做到这一点?
例如,对于前n = 2个产品,结果如下。
InvoiceId StockCode Price
XXX ProductA 199,00
XXX ProductB 78,00
YYY ProductB 78,00
YYY ProductA 199,00
ZZZ ProductA 199,00
ZZZ ProductB 78,00
即,删除了带有ProductC和ProductZ的行。
最后,我想用前n个产品呈现数据,如下所示。
ProductA ProductB
XXX 1 1
YYY 1 1
ZZZ 1 1








暂无数据