2017-03-06 9 views
-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() 

は、いくつかのいずれかは、私が間違っているつもりどこ指摘していただけますか?前もって感謝します!

答えて

3

エラーがある場合は、間違いなく、あなたが使用しているシステムへのフルアクセスを持っていない可能性があります「許可が拒否された」、

OR

チェック使用しているリストインデックスのロジック、 間違った反復/ Rangeはあなたと同じエラーを返します。

または

ルートディレクトリに書き込むための十分な権限がありません。

関連する問題