我没有cav文件,你可以把它输出成一个列表,按照我这个方法来from lxml import etree
import openpyxl
def len_column(dt):
for i in range(1,1000):
if dt.cell(row = 1, column = i).value == None:
return i
def len_row(dt):
for i in range(1,10000):
if dt.cell(row = i, column =1).value == None:
return i
def summary(filename = 'C:\\Users\\Chysial\\Desktop\\Weather.xlsx',year='2018',c_name='tmin'):
df = openpyxl.load_workbook(filename)
dt = df['Sheet1']
title = []
for i in range(1,len_column(dt)):
title.append(dt.cell(1,i).value)
j =0
list_c_name = []
for i in range(len(title)):
if title[i] == c_name:
c_name_num = i
for i in range(2, len_row(dt)):
if dt.cell(row = i,column = 3).value == int(year):
j += 1
list_c_name.append(dt.cell(row = i,column = c_name_num + 1).value)
list_c_name.remove(None)
if list_c_name:
max_num = max(list_c_name)
min_num = min(list_c_name)
sum_num = sum(list_c_name)
else:
max_num = 'None'
min_num = 'None'
sum_num = 'None'
return j,max_num,min_num,sum_num
print(summary())
#我没有cav文件,我可以用openpyxl写个大概意思,你把cav用read变成一个大的列表,列表的值对应openpyxl的value就行了
|