当前位置:网站首页>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 )
边栏推荐
猜你喜欢
面试题详解:用Redis实现分布式锁的血泪史
Install sqlserver2019
How did a fake offer steal $540million from "axie infinity"?
95. (cesium chapter) cesium dynamic monomer-3d building (building)
自动化测试:Robot FrameWork框架90%的人都想知道的实用技巧
一鍵免費翻譯300多頁的pdf文檔
一键免费翻译300多页的pdf文档
QT and OpenGL: loading 3D models using the open asset import library (assimp) - Part 2
Basic learning of SQL Server -- creating databases and tables with code
受限线性表
随机推荐
Pycharm basic settings latest version 2022
QT and OpenGL: load 3D models using the open asset import library (assimp)
postgres timestamp转人眼时间字符串或者毫秒值
【编程题】【Scratch二级】2019.09 绘制雪花图案
webflux - webclient Connect reset by peer Error
第四期SFO销毁,Starfish OS如何对SFO价值赋能?
网上买基金安全么?
C语言学习
Take you hand in hand to build feign with idea
[path planning] use the vertical distance limit method and Bessel to optimize the path of a star
正畸注意事项(持续更新中)
507 field D - extraterrestrial relics
Using Google test in QT
Orthodontic precautions (continuously updated)
【leetcode】day1
Connect diodes in series to improve voltage withstand
如何衡量产品是否“刚需、高频、痛点”
QT creator add JSON based Wizard
Enumeration, simulation, and sorting
The function is really powerful!