当前位置: 首页 > news >正文

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()

http://www.lryc.cn/news/309295.html

相关文章:

  • MCTS代码
  • Java 中notify 和 notifyAll 方法介绍
  • Leetcode :杨辉三角
  • MWC 2024丨美格智能CEO杜国彬出席中国联通创新成果发布会并发表主题演讲
  • 个人建站前端篇(七)vite + vue3企业级项目模板
  • centos7 安装 docker-compose
  • 剑指offer面试题28:对称的二叉树
  • JS:原型与原型链(附带图解与代码)
  • 电子电器架构新趋势 —— 最佳着力点:域控制器
  • C++记录
  • ConcurrentModificationException并发修改异常
  • 小程序事件处理
  • 蓝桥杯-单片机组基础6——定时计数器与外部中断混合使用(附小蜜蜂课程代码)
  • 交友社交软件开发-php交友聊天系统-
  • vue2 开发记录
  • QML中表格中数据获取
  • 【mysql 数据库事务】开启事务操作数据库,写入失败后,不回滚,会有问题么? 这里隐藏着大坑,复试,面试时可以镇住面试老师!!!!
  • Go语言的100个错误使用场景(55-60)|并发基础
  • 钉钉机器人发送折线图卡片 工具类代码
  • 基于springboot的大型商场应急预案管理系统论文
  • 强化学习嵌入Transformer(代码实践)
  • 决定西弗吉尼亚州地区版图的关键历史事件
  • LeetCode_22_中等_括号生成
  • Verilog(未完待续)
  • 【Linux实践室】Linux初体验
  • Flutter中高级JSON处理:使用json_serializable进行深入定制
  • 华为OD技术面试案例4-2024年
  • 【TestNG】(4) 重试机制与监听器的使用
  • “智农”-高标准农田
  • 利用 lxml 库的XPath()方法在网页中快速查找元素