简体   繁体   English

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

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

Here is how my data looks: DataFrame这是我的数据的外观: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我想找到 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')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Pandas dataframe 在其他列中找到每个组的不同值计数 - Pandas dataframe find distinct value count for each group in other columns 将 dataframe 按两列分组,然后根据其中一组查找平均计数 - Group dataframe by two columns and then find average count based on one of the groups Pandas数据框 - 根据两列的ID查找匹配的行 - Pandas dataframe - find matching rows, based on IDs from two columns 如何根据多列值对 pandas 数据框进行分组、计数和取消堆叠? - How to group , count, and unstack a pandas dataframe based on multiple columns values? 如何过滤和分组 pandas DataFrame 以获得两列组合的计数 - How to filter and group pandas DataFrame to get count for combination of two columns 如何在Pandas数据帧中按小时分组行? - How to group rows by hour of day in Pandas dataframe? 如何根据每个组具有 n 行数的特定列在 pandas 中分组? 如果可能,还要从原始 dataframe 中删除? - How to group by in pandas based on specific columns where each group has n number of rows? Also delete from the original dataframe IF POSSIBLE? 每天获取一个非常大的 Pandas DataFrame 中所有行的总和,这些行在两个特定列中匹配 - For each day get the sum of all rows in a very large Pandas DataFrame which match in two specific columns 如何根据两列中的值删除 pandas dataframe 中的行? - How to remove rows in a pandas dataframe based on values in two columns? python:基于 pandas dataframe 中两列(变量)中的两个数组行的频率计数 - python: frequency count based on two array-rows in two columns (variables) in pandas dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM