Python 实现Excel自动化办公(中)

03-03 阅读 0评论

在上一篇文章的基础上进行一些特殊的处理,这里的特殊处理主要是涉及到了日期格式数据的处理(上一篇文章大家估计也看到了日期数据的处理是不对的)以及常用的聚合数据统计处理,可以有效的实现你的常用统计要求。代码如下:

Python 实现Excel自动化办公(中),Python 实现Excel自动化办公(中),词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,Python,要求,第1张
(图片来源网络,侵删)
#统计员工男女比例def get_sex_percent():    sexlist=[]    for rows in range(table.nrows-1):        sexlist.append(table.cell(rows+1,2).value)    print(sexlist)    print("the 男女比 is:",round(sexlist.count("男")/sexlist.count("女"),2))​​​​​​
输出结果为:['男', '女', '男', '男', '男', '男', '男', '女', '女', '男', '男', '女', '男', '男', '男', '女', '男', '女', '男', '男']the 男女比 is: 2.33
#时间数据类型的处理def get_date():    for rows in range(table.nrows):        for cols in range(table.ncols):            if(table.cell(rows,cols).ctype==3):                date=xlrd.xldate_as_datetime(table.cell(rows,cols).value,0)                print(date)​​​​​​
#最后一列数据统计处理def get_statics():   sum=0   list1=[]   for rows in range(table.nrows-1):       sum+=int(table.cell(rows+1,table.ncols-1).value)       list1.append(int(table.cell(rows+1,table.ncols-1).value))       # print(table.cell(rows+1,8).value)       print("the sum is:",sum) #求和       print("the avg is:", round(sum /table.ncols, 2)) #取平均值       print("the max is:",sorted(list1)[-1]) #取最大值       print("the min is:",sorted(list1)[0]) #取最小值       if(len(list1)%2==0): #判断列表长度是奇还是偶,来取中位数           print("the median is:",(list1[int(len(list1)/2)]+list1[int(len(list1)/2+1)])/2)       else:           print("the median is:",list1[int((len(list1)+1)/2)])
if __name__ == '__main__': get_date() get_statics()

Python 实现Excel自动化办公(中)

Python 实现Excel自动化办公(中),Python 实现Excel自动化办公(中),词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,Python,要求,第3张
(图片来源网络,侵删)
Python 实现Excel自动化办公(中),Python 实现Excel自动化办公(中),词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,Python,要求,第4张
(图片来源网络,侵删)

免责声明
本网站所收集的部分公开资料来源于AI生成和互联网,转载的目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。

发表评论

快捷回复: 表情:
评论列表 (暂无评论,人围观)

还没有评论,来说两句吧...

目录[+]