我有一个要求,我要在其中计算值并将它们放在数据透视表中.
I have a requirement where in I am trying to count the values and Put them in the pivot table.
这是我的数据框,
Cola Colb Apple Rippened Orange Rippened Apple UnRippened Mango UnRippened我希望输出是这样的,
Rippened UnRippened Apple 1 1 Mango 0 1 Orange 1 0请分享您的想法.
推荐答案IIUC:
In [178]: d.pivot_table(index='Cola', columns='Colb', aggfunc='size', fill_value=0) Out[178]: Colb Rippened UnRippened Cola Apple 1 1 Mango 0 1 Orange 1 0