温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Python如何实现Excel自动化办公

发布时间:2021-11-15 15:26:39 来源:亿速云 阅读:145 作者:柒染 栏目:大数据

这期内容当中小编将会给大家带来有关Python如何实现Excel自动化办公,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

这里的特殊处理主要是涉及到了日期格式数据的处理以及常用的聚合数据统计处理,可以有效的实现你的常用统计要求。代码如下:

#统计员工男女比例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自动化办公了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI