我正在计算我保存在文件夹中的大约50个excel文件的x、y和z列的平均值和标准值。每个excel文件的第一列有x值,第二列有y值,第三列有z值。我使用这个脚本,但它一直给我错误。所有文件都保存为“.xls”。如果你们能帮上忙的话,我可以帮上忙。以下是脚本和错误:import xlrd
import numpy
import os
path = "E:\\hello\\Patient"
dirList=os.listdir(path)
f = open('E:\\hello\\try.xls', 'w')
f.write('Patient_ID, Xavg, xstd, yavg, ystd, zavg, ystd')
f.write("\n")
##print dirList
##i = 0
Col_values=[]
for file in dirList:
fullpath = os.path.join(path,file)
## print fullpath
if os.path.isfile(fullpath) == 1:
wb = xlrd.open_workbook(fullpath)
sh = wb.sheet_by_index(0)
f.write(str(file))
f.write(", ")
for i in range(0,3):
for j in range(sh.nrows):
Col_values.append(sh.cell(j,i).value)
a = numpy.average(Col_values)
b = numpy.std(Col_values)
f.write(str(a))
f.write(", ")
f.write(str(b))
f.write(", ")
f.write("\n")
f.close()