简体   繁体   English

没有重复,计算每天进入的人数

[英]Without duplication, count number of people entering each day

I am working with a worksheet as below: 我正在使用如下工作表:

Date/Time      Badge       Name
10/31/2013    
8:01:02 AM     131078      YEO, Nita
8:03:17 AM     415416      PEH, Wei
10/30/2013    
8:11:02 AM     131098      LEE, Alice
8:53:17 AM     215416      EG, shi
...
  1. I want to count the number of people entered without dupication in one day. 我想计算一天内没有重复输入的人数。 Just are the date, not the exact time. 只是日期,而不是确切的时间。 Each person has a unique Badge number. 每个人都有一个独特的徽章编号。

  2. After that, I have another worksheet with all the empoyees` Badge number. 在那之后,我有另一张包含所有empoyees`徽章编号的工作表。 I want to compare the peoople entered with this sheet to exclude the visitors, ie the people inside both sheets remain. 我想比较用这张表输入的人员来排除访客,即两张床单内的人员仍然存在。 Then count how many. 然后计算多少。

To sum up, in one month, count number of empoyees but not visitors entered in each day. 总而言之,在一个月内,计算每一天进入的访客数量,而不是访客数量。 and plot the number against date. 并根据日期绘制数字。

How this can be done using excel, pivot table or VBA? 如何使用excel,数据透视表或VBA完成此操作?

Something like this 像这样的东西

from collections import defaultdict

# collect all visitors in a dictionary where the key is the date, and
# the value is a set of badge numbers
visitorsPerDay = defaultdict(set)

# store the last read date value
currentDate = None

with open('filename') as f:
    for line in f:
        # if the line is 10 characters long, it’s a date line
        if len(line.strip()) == 10:
            # store the date value
            currentDate = line.strip()
        elif currentDate:
            # extract the badge number; if the file is tab
            # separated, even better: split by \t
            time, badge, _ = (part.strip() for part in line.split('   ', 2))

            # add the badge number to the set within the dictionary
            visitorsPerDay[currentDate].add(badge)

# now for every date, count the number of (unique) visitors
for date, visitors in visitorsPerDay.items():
    print(date, len(visitors))

In Excel, add a column on the extreme left and, assuming 'Date/Time' is then in B1, in A2 enter =IF(ISBLANK(C2),B2,A1) and copy down to suit. 在Excel中,在最左边添加一列,假设'日期/时间'在B1中,在A2中输入=IF(ISBLANK(C2),B2,A1)并向下复制以适应。 Copy ColumnA and Paste Special, Values over the top. 将ColumnA和Paste Special,Values复制到顶部。 Filter ColumnC for (Blanks) and delete the selected rows. 过滤ColumnC(空白)并删除所选行。 Add Date in A1. 在A1中添加Date Your data layout should now be more-or-less as @Brett recommended. @Brett推荐,您的数据布局现在应该或多或少。


Use a lookup function to add to each row indication of whether or not Visitor. 使用查找功能向每行添加是否访问者的指示。

A PivotTable constructed as indicated from the source data as on the left in the image will show the number of unique badge visits by day: 根据图像左侧的源数据指示构建的数据透视表将按天显示唯一徽章访问次数:

SO19764305的例子

Filter to select only n in the Report Filter field and you have the equivalent for employees only. 过滤以仅在“报告过滤器”字段中选择n ,并且仅具有员工的等效项。

For monthly figures use the Group (on the Quick Menu), By, Months facility. 对于每月数字,请使用组(在快速菜单上),按月,月份设施。

For charting, remove Badge from Row Labels and Insert a suitable chart. 对于图表,从行标签中删除徽章并插入合适的图表。

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

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