简体   繁体   中英

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. 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?

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. Copy ColumnA and Paste Special, Values over the top. Filter ColumnC for (Blanks) and delete the selected rows. Add Date in A1. Your data layout should now be more-or-less as @Brett recommended.


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.

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.

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