本文主要是介绍python操作读取excl并进行数据统计,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
判断是否单元格是否为数字字母内容
bool(re.match(r'^[a-zA-Z0-9]+$', row[rownum + 1]))
判断行是否为float类型
type(row[rownum]) == float
获取workboot中sheet的名称
sheet.name
场景读取某个文件夹下的excl并统计每个sheet页中存在满足条件的 记录数
import re
import os
import xlrddef get_files_in_folder(folder_path):file_names = os.listdir(folder_path)return file_names
def readExcl(path):# 打开工作表workbook = xlrd.open_workbook(path)# 获取所有的工作薄sheets = workbook.sheet_names()# 获取sheet总个数num = workbook.nsheetscountLine = 0# 返回的结果集for i in range(num):sheet = workbook.sheets()[i]# python3.8用法rows = sheet.nrowsrownum = 0line = 0for i in range(rows):row = sheet.row_values(i)if rownum == 0:for td in range(len(row)):if row[td] == "xx监测日期":rownum = tdelif type(row[rownum]) == float and bool(re.match(r'^[a-zA-Z0-9]+$', row[rownum + 1])): #条件判断line = line + 1if line > 0:print(sheet.name + " " + str(line))countLine = countLine+linereturn countLineif __name__ == '__main__':path= "C:\\path\\"files = get_files_in_folder(path)cl = 0for file in files:cl = readExcl(path+file)+clprint("总数:"+str(cl))
这篇关于python操作读取excl并进行数据统计的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!