考勤数据统计

读取考勤数据

import pandas as pd
myKq = pd.read_excel("kq.xlsx")
myKq[u'打卡日期'].values
array([u'2017-12-29 17:33:26', u'2017-12-29 17:31:54',
       u'2017-12-29 17:28:55', ..., u'2017-01-03 17:05:55',
       u'2017-01-03 12:32:11', u'2017-01-03 10:24:25'], dtype=object)
import numpy as np
#myKq.insert(1,'city',myKq['address']) #先复制原来的列
daytime = myKq[u'打卡日期'].map(lambda x:x.split(' ')) #分别处理新旧两列
day, time = [],[]
for d in daytime:
    day.append(d[0])
    time.append(d[1])
myKq['day'] = day
myKq['time'] = time
myKq.tail()
import matplotlib.pyplot as plt
from datetime import datetime
from matplotlib.font_manager import FontProperties  
font = FontProperties(fname=r"C:\\WINDOWS\\Fonts\\simsun.ttc", size=14)

def getMin(arrtime):
    a = (arrtime).split(":")
    return (float(a[0])-9)*60+float(a[1])
plt.figure()
def getMax(arrtime):
    a = (arrtime).split(":")
    return (float(a[0])-18)*60+float(a[1])

df = myKq["time"].groupby(myKq['day'])

night = df.max().map(lambda x:getMax(x))
morning = df.min().map(lambda x:getMin(x))
colors = np.array(['g']*morning.size)
dic_c_l = {'g':'work day', 'r':'friday', 'b':'weekend'}
for index, day in enumerate(morning.index):
    week = datetime.strptime(day, '%Y-%m-%d').weekday()
    if (week+1 == 5):
        colors[index] = 'r'
    elif (week+1==6 or week+1==7):
        colors[index] = 'b'
fig = plt.figure(figsize=(14,5))
ax1 = fig.add_subplot(121)

plt.xlabel(u'上班(day)',fontproperties=font)  
plt.ylabel(u'加班时间',fontproperties=font)  

for index, value in enumerate(dic_c_l.keys()):
    temp = np.where(colors==value)
    ax1.scatter(temp, night.values[temp], c=value,marker= 'o', label= dic_c_l[value])
ax1.legend(loc='upper left')

ax2 = fig.add_subplot(122) 
ax2.hist(night, bins = 40, normed= 0)


plt.xlabel(u'加班分钟数',fontproperties=font)
plt.ylabel(u'次数',fontproperties=font)

plt.show()
fig = plt.figure(figsize=(14,5))
ax1 = fig.add_subplot(121)

colors = np.array(['g']*morning.size)
dic_c_l = {'g':'work day', 'r':'monday', 'b':'weekend'}
for index, day in enumerate(morning.index):
    week = datetime.strptime(day, '%Y-%m-%d').weekday()
    if (week+1 == 1):
        colors[index] = 'r'
    elif (week+1==6 or week+1==7):
        colors[index] = 'b'
        
plt.xlabel(u'上班(day)',fontproperties=font)  
plt.ylabel(u'迟到时间',fontproperties=font)  

for index, value in enumerate(dic_c_l.keys()):
    temp = np.where(colors==value)
    ax1.scatter(temp, morning.values[temp], c=value,marker= 'o', label= dic_c_l[value])
ax1.legend(loc='upper left')

ax2 = fig.add_subplot(122) 
ax2.hist(morning.values, bins = 80, normed= 0)


plt.xlabel(u'迟到分钟数',fontproperties=font)
plt.ylabel(u'次数',fontproperties=font)
plt.show()
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • # -*- coding: utf-8 -*- from __future__ import division f...
    小豆角lch阅读 1,576评论 0赞 1
  • 第二章 python基础 1、数据类型和变量 (1)数据类型:整数、浮点数、字符串、转义字符、布尔值、空值 (2)...
    papaha阅读 214评论 0赞 0
  • 1.分布式表示:全连接的形式,而非结果。2.perceptrons, back propagation, deep...
    姚屹晨阅读 256评论 0赞 0
  • 昨天说多态放在类中,是错误的。python不允许函数重名。 多态的实现 def he (x=0,y=0,z=0,i...
    李响lx阅读 302评论 0赞 0
  • 今天陪老婆和两个女儿去看了奥斯卡提名的电影:雄狮,收获好多:1:每个人的命运都不同,从出生的那一刻起就已经注定了。...
    Martin_马丁阅读 356评论 0赞 4

友情链接更多精彩内容