带有熊猫的数据透视表

时间:2020-07-10 07:13:57

标签: pandas pivot

我正在尝试使用分类变量创建表,但找不到计算每个单元格中值的方法。

我已经尝试过使用数据透视,分组,堆栈,索引,但是它们都没有给我想要的结果。我找不到进行这些分组的方法。

这是我的数据的简化版本:

> Project      ID   Status         Modem        Computer
P1             1    Installed      Type1        Dell
P1             2    Installed      Type1        Dell
P1             3    Installed      Type1        Lenovo
P1             4    Installed      Type2        Dell
P1             5    Installed      Type2        Dell
P1             6    Installed      Type1        HP
P1             7    Installed      Type1        Lenovo
P1             8    Installed      No modem     Dell
P1             9    Not Installed  No modem     No
P1            10    Not Installed  No modem     No
P1            11    Not Installed  No modem     No
P2            12    Installed      Type1        Lenovo
P2            13    Installed      Type2        Lenovo
P2            14    Not Installed  No modem     No
P3            15    Installed      Type1        Dell

我希望摘要大致像这样:

         Status                                     Status  
         Installed                                  Not Installed       
Project  Modem:Type1  Modem:Type2  Modem:No modem   Modem:Type1  Modem:Type2  Modem: No modem
P1       5            2            4                0            0            0

P2       2            0            0                0            0            1
                        
P3       1            0            0                0            0            0

        

0 个答案:

没有答案