简体   繁体   中英

How to group pandas dataframe rows based on two columns to find the count for each day?

Here is how my data looks: 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

I want to find the count of the number of rows each day for Plaza ID = 1420

I used the following code:

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

the output of which is the following:

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

But I do not want the count of false results to be printed, can anyone tell me what am i doing wrong?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM