如何基于两列对熊猫数据框行进行分组以查找每天的计数?

时间:2020-02-02 21:45:23

标签: python python-3.x pandas csv dataframe

这是我的数据的外观: 数据框

           TagID                           PlazaEntryTime                      PlazaID
     0   2844106899                     9/29/19 9:31:06 PM                       1420
     1   2844106896                     10/29/19 9:31:06 PM                      1421
     2   2844106896                     9/29/19 9:31:06 PM                       1440
     3   2844106896                     12/29/19 9:31:06 PM                      1422

我想查找Plaza ID = 1420每天的行数计数

我使用了以下代码:

df['PlazaEntryTime'].groupby([df.PlazaEntryTime.dt.day,df.PlazaId==1420]).agg('count')

其输出如下:

 PlazaEntryTime    PlazaId        Count
     9             False            0
                   True             2
     10            False            1
                   True             0
     12            False            1
                   True             0

但是我不希望打印错误结果的计数,有人可以告诉我我在做什么错吗?

1 个答案:

答案 0 :(得分:0)

df[df['PlazaID']==1420].groupby(df.PlazaEntryTime.dt.day)['TagID'].agg('count')