import csv
from math import sqrt
import os
class MaxiAverageCalculator(object):
def __init__(self):
self.ncols = 3
self.nrows = 0
self.s = [0.0, 0.0, 0.0]
self.s2 = [0.0, 0.0, 0.0]
def run(self, fullpath):
with open(fullpath, "rb") as infile:
reader = csv.reader(infile, delimiter=",")
self.colnames = list(next(reader))
assert len(self.colnames) == 3
for row in reader:
L = [ float(x) for x in row ]
assert len(L) == 3
for i, x in enumerate(L):
self.s[i] += x
self.s2[i] += x * x
self.nrows += 1
self.avg = [x/self.nrows for x in self.s]
self.std = [ sqrt((y/self.nrows) - a * a) for a, y in zip(self.avg, self.s2) ]
print "Results for {0}".format(fullpath)
for name, a, s in zip(self.colnames, self.avg, self.std):
f.write(str(a))
f.write(", ")
f.write(str(s))
f.write("\n")
## print "{0}: avg = {1:.5f}, std = {2:.5f}".format(name, a, s)
## print
if __name__ == "__main__":
path="A:\\yoyo\\heyy\\folder"
f=open("A\\yoy\\save.xls")
f.write("xavg, xstd, yavg, ystd, zavg, zstd")
f.write("\n")
dirList=os.listdir(path)
for file in dirList:
fullpath=os.path.join(path,file)
calc = MaxiAverageCalculator()
calc.run(fullpath)
그래서 평균 및 x, y, z를 별도의 Excel 파일로 인쇄하려고합니다 ...이 스크립트는 온라인에 있습니다. 하지만 작동하지 않는 것 같아 ... 도와주세요파일, 파이썬 엑셀 인쇄
"온라인에서이 스크립트를 얻었지만 작동하지 않는 것 같습니다."어떻게해야하는지에 대해 이해하고 있습니까? 이 사이트는 프로그램을 작성하는 사용자를위한 사이트입니다. 프로그램을 실행하려는 사람들을위한 사이트가 아닙니다. –
@Temesgen Abba : 대답으로 생각한 방법을 게시하고 받아들이면 모든 사용자가 여기에 대한 답변을 찾는 데 도움이됩니다 – JMax