-1
我試圖通過刪除'?'來預處理一個數據集。從每個數據點開始計算每個色譜柱的平均值和標準偏差。我收到以下錯誤:計算python中每一列csv文件的均值和標準差
IOError: [Errno 13] Permission denied: 'outputFile'
這裏是我的代碼:
import csv
import sys
import numpy as np
from collections import Counter
class PreProcessDataSet:
def standardize(self) :
special_chars = set('?')
inputFile = open(sys.argv[1], 'rb')
print ('Input file as entered is : ', inputFile)
outputFile = open(sys.argv[2],'wb')
print ('Output file as entered is : ', outputFile)
writer = csv.writer(outputFile)
for row in csv.reader(inputFile):
if not set(''.join(row)) & special_chars:
writer.writerow(row)
print row
column_totals = Counter()
with open('outputFile') as f:
reader = csv.reader(f)
row_count = 0.0
for row in reader:
for column_idx, column_value in enumerate(row):
try:
n = float(column_value)
column_totals[column_idx] += n
except ValueError:
print "Error -- ({}) Column({}) could not be converted to float!".format(column_value,
column_idx)
row_count += 1.0
# row_count is now 1 too many so decrement it back down
row_count -= 1.0
column_indexes = column_totals.keys()
column_indexes.sort()
# calculate per column averages using a list comprehension
averages = [column_totals[idx]/row_count for idx in column_indexes]
print averages
obj = PreProcessDataSet()
obj.standardize()
能有人請指出我要去的地方錯了嗎?提前致謝!