テキストファイルから平均値を検索しようとしています。テキストファイルには数値の列があり、各列の平均を求めたいと思います。私はfollwoingエラーを取得する: はIndexError:リストインデックス範囲IndexError:リストのインデックスが範囲外です。PYTHON(forループを使用しない)
のうち、私が使用していたコードは次のとおりです。
import os
os.chdir(r"path of my file")
file_open = open("name of my file", "r")
file_write = open ("average.txt", "w")
line = file_open.readlines()
list_of_lines = []
length = len(list_of_lines[0])
total = 0
for i in line:
values = i.split('\t')
list_of_lines.append(values)
count = 0
for j in list_of_lines:
count +=1
for k in range(0,count):
print k
list_of_lines[k].remove('\n')
for o in range(0,count):
for p in range(0,length):
print list_of_lines[p][o]
number = int(list_of_lines[p][o])
total + number
average = total/count
print average
エラーがラインに
length = len(list_of_lines[0])
ある私なら、私に知らせてください。これ以上の情報を提供することはできません。
'len(list_of_lines [0])'、特に 'list_of_lines [0]'は 'list_of_lines = []'の直後に何を期待していますか? –
'list_of_lines = []'と 'length = len(list_of_lines [0])'は良く見えません。 –
'list_of_lines = [] length = len(list_of_lines [0])'あなたは何をすると思いますか? 「長さ」にはどのような価値がありますか? – njzk2