Home >Backend Development >Python Tutorial >Example of implementing simple EXCEL data statistics using python
Task:
Use python time to perform a simple statistical task - count how many men and women there are.
Materials used: xlrd Its function-read excel table data
Code:
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)
The above The example of using Python to implement simple EXCEL data statistics is all the content shared by the editor. I hope it can give you a reference, and I also hope you will support the PHP Chinese website.
For more related articles on examples of using python to implement simple EXCEL data statistics, please pay attention to the PHP Chinese website!