Solution:
Somewhere in your text file, a line has the word id
in it, which can't really be converted to a number.
Your test code works because of the word id
isn't present in line 2
.
If you want to catch that line, try this code. I cleaned your code up a tad:
import os, sys
from scipy import stats
import numpy as np
for index, line in enumerate(open('data2.txt', 'r').readlines()):
w = line.split(' ')
l1 = w[1:8]
l2 = w[8:15]
try:
list1 = map(float, l1)
list2 = map(float, l2)
except ValueError:
print 'Line {i} is corrupt!'.format(i = index)'
break
result = stats.ttest_ind(list1, list2)
print result[1]