相关疑难解决方法(0)

ValueError:无法将字符串转换为float:id

我正在运行以下python脚本:

#!/usr/bin/python

import os,sys
from scipy import stats
import numpy as np

f=open('data2.txt', 'r').readlines()
N=len(f)-1
for i in range(0,N):
    w=f[i].split()
    l1=w[1:8]
    l2=w[8:15]
    list1=[float(x) for x in l1]
    list2=[float(x) for x in l2]
    result=stats.ttest_ind(list1,list2)
    print result[1]
Run Code Online (Sandbox Code Playgroud)

但是我得到的错误如下:

ValueError: could not convert string to float: id
Run Code Online (Sandbox Code Playgroud)

我很困惑.当我在交互式部分中只尝试一行时,而不是使用脚本循环:

>>> from scipy import stats
>>> import numpy as np
>>> f=open('data2.txt','r').readlines()
>>> w=f[1].split()
>>> l1=w[1:8]
>>> l2=w[8:15]
>>> list1=[float(x) for x in l1]
>>> list1
[5.3209183842, 4.6422726719, 4.3788135547, 5.9299061614, 5.9331108706, 5.0287087832, 4.57...]
Run Code Online (Sandbox Code Playgroud)

我运作良好.

任何人都可以解释一下吗?谢谢

python string floating-point

61
推荐指数
7
解决办法
59万
查看次数

标签 统计

floating-point ×1

python ×1

string ×1