用 python实现简单EXCEL数据统计

任务:

用python时间简单的统计任务-统计男性和女性分别有多少人。

用到的物料:xlrd 它的作用-读取excel表数据

代码:

import xlrd
workbook = xlrd.open_workbook('demo.xlsx') #打开excel数据表
SheetList = workbook.sheet_names()#读取电子表到列表
SheetName = SheetList[0]#读取第一个电子表的名称
Sheet1 = workbook.sheet_by_index(0) #电子表索引从0开始
Sheet1 = workbook.sheet_by_name(SheetName) #实例化电子表对象

m=0
f=0

for i in range(Sheet1.nrows): 
     rows = Sheet1.row_values(i)
     if rows[2] == 'Male':
             m+=1
     elif rows[2] == 'Female':
             f+=1
print('Male:', m, 'Female:', f)

 

相关文章:

  • 2022-12-23
  • 2021-12-04
  • 2021-12-18
  • 2022-12-23
  • 2021-10-04
  • 2022-12-23
  • 2022-12-23
  • 2021-06-06
猜你喜欢
  • 2022-01-26
  • 2021-12-02
  • 2021-10-24
  • 2022-12-23
  • 2022-12-23
  • 2022-02-16
相关资源
相似解决方案