Post
Python
How to resolve the error “could not convert string to float: id”?
here is my code which is showing the same error called “could not convert string to float: id”
import os,sys
from scipy import stats
import numpy as np
f=open('data2.txt', 'r').readlines()
N=len(f)-1
for j in range(0,N):
w=f[j].split()
l1=w[1:8]
l2=w[8:15]
li1=[float(y) for y in l1]
li2=[float(y) for y in l2]
result=stats.ttest_ind(li1,li2)
print result[1]
Posted on 26th April 2024
I have cleaned your code this may work now
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:
li1 = map(float, l1)
li2 = map(float, l2)
except ValueError:
print 'Line {j} is corrupt!'.format(j = index)'
break
result = stats.ttest_ind(li1, li2)
print result[1]
STILL GOT QUERIES?