[英]Pandas dataframe find distinct value count for each group in other columns
[英]How to group pandas dataframe rows based on two columns to find the count for each day?
這是我的數據的外觀: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
但我不想打印錯誤結果的數量,誰能告訴我我做錯了什么?
df[df['PlazaID']==1420].groupby(df.PlazaEntryTime.dt.day)['TagID'].agg('count')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.