当前位置:网站首页>Fully automated processing of monthly card shortage data and output of card shortage personnel information
Fully automated processing of monthly card shortage data and output of card shortage personnel information
2022-07-07 23:56:00 【Ali Yiyang】
Whether it is school or work, attendance statistics will be made , Some schools or companies will have too many missing cards every month ( For example, more than three times ) To punish the personnel . Some companies also stipulate that basic level employees should submit logs on weekdays 、 Management personnel shall submit weekly or monthly reports , Those who submit less shall be punished . If the company HR Handle the personnel log or card shortage data one by one , It will be a time-consuming and boring job .
This article provides a method to automatically handle attendance and missing logs . No need to install Python, No need to learn Python grammar , As long as you can create new folders on your computer , Click the file to realize the statistical output of attendance and log missing list . Next, let's take a look at the implementation steps .
One 、 Effect display
1 Realization effect
First, let's take a look at the implementation effect .
The general implementation steps are as follows :
step 1: stay D New disk “ Monthly card shortage data processing “ Folder ( Fixed in the code , This folder must be created ).
step 2: Deal with the missing attendance exe Files and raw data files are put into step1 New folder .
step 3: Click on exe file , Will automatically come out csv Results file , The specific format is as follows :
2 Raw data template
The original data file needs to be ” Determine whether to submit the log 2.xlsx“, The raw data used in this article are as follows ( The header shall be named as follows ):
notes : If you need the original data of this article 、 And running directly to get the results exe file , You can reply to this official account “ Missing card ”, Free access to .
The person filling in refers to the name of the student or employee , If the Department is a student, you can fill in a class . Filling time refers to the filling time of the log , Date refers to the actual date of the log . In case of clock in , For both dates, you can fill in the actual punch in date . In case of clock in , Today's completion column can be left blank .
If you want to store the annual data of employees' clocking in the original file , But I want to count the card shortage data of a certain month . Just put the month you want to count on the first line of the date , The code has filtered the data sub box of the same month and year according to the first line of the date . To set a scheduled task , Send the running results to relevant personnel by regular email , You can trust me in the official account. .
Two 、 Code details
For partial understanding Python To a friend , If there is a personalized need , You can fine tune your code to meet your requirements . Next, the code to realize the above functions is described in detail .
1 Import library
First, import the library to be loaded in this article , If you don't have some libraries installed , Cause the running code to report an error , Can be in Anaconda Prompt of use pip Method installation .
# -*- coding: UTF-8 -*-
''' Code usage : Processing card missing data author : Ali Yiyang official account : The code of Ali Yiyang '''
import os
import calendar
import numpy as np
import pandas as pd
from datetime import datetime
from xlrd import xldate_as_tuple
from chinese_calendar import is_workday
from chinese_calendar import is_holiday
from chinese_calendar import get_holiday_detail
This paper applies to os、calendar、numpy、pandas、datetime、xlrd、chinese_calendar library .
os The library can set the location where files are read .
calendar and chinese_calendar Library is a date processing library .
numpy and pandas The library handles data frames .
xlrd and datetime Library processing time .
2 Define time processing functions
Then apply xlrd and datetime The function in the library defines the time processing function , Convert the time stamp or the time with hour, minute and second into the time containing only the month, year and day .
def num_to_date(x):
''' Date processing function Convert the time stamp or the time with hour, minute and second into the time containing only the month, year and day '''
try:
x1 = datetime(*xldate_as_tuple(x, 0)).strftime('%Y-%m-%d')
except:
x1 = datetime.date(x).strftime('%Y-%m-%d')
return x1
The purpose of defining the unified time of adult month and day is to facilitate the operation of subsequent code .
3 Read data to adjust date format
Then read the data , Use the time processing function defined in Section 2 to process the filling time and date .
# Reading data
os.chdir(r'D:\ Monthly card shortage data processing ')
date = pd.read_excel(' Determine whether to submit the log 2.xlsx', sheet_name='Sheet1')
# Adjust date format
date[' Filling time '] = date[' Filling time '].apply(num_to_date)
date[' date '] = date[' date '].apply(num_to_date)
The original partial data are as follows :
Some data obtained by calling the time processing function are as follows :
4 Calculate the number of working days
Then take the first value of the date column of the data frame , Get the year / month information to be counted . Obtain the number of working days of the month according to the information of the month .
# Take out the year and year you want to see the missing card information
y_m1 = date[' date '][0][0:7]
def sele_ym(x, y_m=y_m1):
''' Judge whether the date in the data frame is a month '''
if x.find(y_m)>=0:
return True
# Find the working days of the month , Find the number of working days
days = calendar.Calendar().itermonthdates(int(y_m1.split('-')[0]), int(y_m1.split('-')[1]))
mth_nwkdays = [] # Non working days
mth_wkdays = [] # Working day
mth_days = [] # All dates
for day in days:
if str(day).find(y_m1)>=0:
#print(str(day))
mth_days.append(str(day))
if is_workday(day)>0:
mth_wkdays.append(str(day))
else:
mth_nwkdays.append(str(day))
work_days = len(mth_wkdays) # Working days
Compare the working days with the actual clock in or log in days of the current month , If the actual value is less than the theoretical value , It means that the employee is missing a card or asking for leave . Because most of the employees clock in or write logs normally , At this time, the manual screening of the employees who lack cards has greatly reduced the screening area . If there are special code requirements , Need help , You can trust me in the official account. .
5 Get the missing card list
Finally, call the function to get the missing card list , It mainly compares each filling date with the actual working date .
# Define the function to obtain card shortage information
def stat_dail_short(date, y_m1, work_days):
''' date: Large data table for storing logs y_m1: month work_days: Number of working days in the month '''
qk_file = []
date_m = date[date[' date '].apply(sele_ym)==True]
for i in set(date_m[' Filled by ']):
sub_date = date_m[date_m[' Filled by '] == i]
if len(sub_date[' date '])<work_days:
qk = str(set(sub_date[' Filled by '])) + str(set(sub_date[' department '])) + ' Missing '+ str((work_days-len(sub_date[' date ']))) + ' Second card ' + '; The card shortage date is :'+ str(set(mth_wkdays)^set(sub_date[' date ']))
qk_file.append(qk)
print(set(sub_date[' Filled by ']), set(sub_date[' department ']), ' Missing %d Second card '%(work_days-len(sub_date[' date '])), '; The card shortage date is :', set(mth_wkdays)^set(sub_date[' date ']),sep='')
qk_file_1 = pd.DataFrame(qk_file)
qk_file_1.columns = [' Missing card information ']
qk_file_1.to_csv(y_m1+' Missing card list '+'.csv', encoding='gbk')
# Call the function to get the missing card list
stat_dail_short(date, y_m1, work_days)
Get the results :
{
' Zhang Jike '}{
' Ministry of sports '} Missing 5 Second card ; The card shortage date is :{
'2022-04-11', '2022-04-29', '2022-04-22', '2022-04-18', '2022-04-21'}
{
' Andy '}{
' Robbery Department '} Missing 1 Second card ; The card shortage date is :{
'2022-04-20'}
{
' Liu shiwen '}{
' Ministry of sports '} Missing 2 Second card ; The card shortage date is :{
'2022-04-18', '2022-04-28'}
The data in the results are reported by 、 Filling Department 、 Number of card missing 、 The specific card missing date is displayed by splicing . Will csv In the specified folder . If you need to put your name 、 department 、 The number of missing cards and other information shall be separated , Can be in excel By specific conditions , Or adjust the code for implementation .
At the beginning of this article exe File generation method , You can refer to Pinstaller(Python Packaging for exe file ) One article . I'm generating exe There have been errors in the process of , Later, I saw the method on the Internet and said that it was in cmd Run in pip uninstall matplotlib, Run the build again exe The statement will not report an error . It's really successful to follow the online method , Although I don't understand the principle , But thank you very much ! If you don't report an error when packing , It is not recommended to delete matplotlib library .
thus , Fully automated processing of monthly card shortage data , The output of the information of the missing card personnel has been explained , Use your hands to share what you need ta Well .
You may be interested in :
use Python Drawing Picasso
use Python Draw a cloud of words
use Python draw 520 Eternal heart
Python Face recognition — You are the only one in my eyes
Python Draw a nice picture of the starry sky ( Aesthetic background )
【Python】 Valentine's Day confession fireworks ( With sound and text )
use Python Medium py2neo Library operation neo4j, Building the association map
Python Romantic confession source collection ( love 、 The roses 、 Photo wall 、 Advertising under the stars )

边栏推荐
- 每日刷题记录 (十六)
- QT and OpenGL: load 3D models using the open asset import library (assimp)
- 一鍵免費翻譯300多頁的pdf文檔
- Seven years' experience of a test engineer -- to you who walk alone all the way (don't give up)
- 数据湖(十五):Spark与Iceberg整合写操作
- webflux - webclient Connect reset by peer Error
- 【编程题】【Scratch二级】2019.09 制作蝙蝠冲关游戏
- Jisuan Ke - t3104
- Solutions to problems in sqlserver deleting data in tables
- Pigsty:开箱即用的数据库发行版
猜你喜欢
Chisel tutorial - 05 Sequential logic in chisel (including explicit multi clock, explicit synchronous reset and explicit asynchronous reset)
全自动化处理每月缺卡数据,输出缺卡人员信息
BSS 7230 flame retardant performance test of aviation interior materials
Solutions to problems in sqlserver deleting data in tables
一鍵免費翻譯300多頁的pdf文檔
An example analysis of MP4 file format parsing
数据湖(十五):Spark与Iceberg整合写操作
Pycharm basic settings latest version 2022
串联二极管,提高耐压
HB 5469 combustion test method for non-metallic materials in civil aircraft cabin
随机推荐
机器人(自动化)等专业课程创新的结果
Aitm3.0005 smoke toxicity test
Restricted linear table
UIC564-2 附录4 –阻燃防火测试:火焰的扩散
LinkedBlockingQueue源码分析-新增和删除
第四期SFO销毁,Starfish OS如何对SFO价值赋能?
SQL uses the in keyword to query multiple fields
每日刷题记录 (十六)
How did a fake offer steal $540million from "axie infinity"?
Uic564-2 Appendix 4 - flame retardant fire test: flame diffusion
BSS 7230 flame retardant performance test of aviation interior materials
Les mots ont été écrits, la fonction est vraiment puissante!
【编程题】【Scratch二级】2019.03 垃圾分类
C语言学习
Anaconda+pycharm+pyqt5 configuration problem: pyuic5 cannot be found exe
数据库查询——第几高的数据?
Teach you to make a custom form label by hand
P2141 [noip2014 popularization group] abacus mental arithmetic test
一键免费翻译300多页的pdf文档
Go learning notes (2) basic types and statements (1)