久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

ValueError:無法將字符串轉換為浮點數:id

ValueError: could not convert string to float: id(ValueError:無法將字符串轉換為浮點數:id)
本文介紹了ValueError:無法將字符串轉換為浮點數:id的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在運行以下 python 腳本:

I'm running the following python script:

#!/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]

但是我得到了如下錯誤:

However I got the errors like:

ValueError: could not convert string to float: id

我對此感到困惑.當我在交互部分中僅對一行嘗試此操作時,而不是使用腳本進行循環:

I'm confused by this. When I try this for only one line in interactive section, instead of for loop using script:

>>> 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...]

效果很好.

誰能解釋一下這個?謝謝.

Can anyone explain a little bit about this? Thank you.

推薦答案

顯然您的某些行沒有有效的浮點數據,特別是某些行包含無法轉換為的文本 id漂浮.

Obviously some of your lines don't have valid float data, specifically some line have text id which can't be converted to float.

當您在交互式提示中嘗試時,您只嘗試第一行,因此最好的方法是打印出現此錯誤的行,您會知道錯誤的行,例如

When you try it in interactive prompt you are trying only first line, so best way is to print the line where you are getting this error and you will know the wrong line e.g.

#!/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]
    try:
        list1=[float(x) for x in l1]
        list2=[float(x) for x in l2]
    except ValueError,e:
        print "error",e,"on line",i
    result=stats.ttest_ind(list1,list2)
    print result[1]

這篇關于ValueError:無法將字符串轉換為浮點數:id的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Python 3 Float Decimal Points/Precision(Python 3 浮點小數點/精度)
Converting Float to Dollars and Cents(將浮點數轉換為美元和美分)
What are some possible calculations with numpy or scipy that can return a NaN?(numpy 或 scipy 有哪些可能的計算可以返回 NaN?)
Python float to ratio(Python浮動比率)
How to manage division of huge numbers in Python?(如何在 Python 中管理大量數字的除法?)
mean from pandas and numpy differ(pandas 和 numpy 的意思不同)
主站蜘蛛池模板: 亚洲国产精品久久久 | 色综合天天 | 四虎久久久 | 一级黄色网 | 国产精品永久久久久久久久久 | 国产美女视频 | 国产一区二区三区精品视频 | 欧美色图一区 | 久久精品国产成人av | 午夜视频一区 | 日日夜夜天天操 | 精品第一页 | 四虎在线免费视频 | 日韩成人精品 | 日韩精品视频网站 | 免费91| 秋霞一区二区三区 | 天天爱天天色 | 欧美91 | 日韩黄色av | 在线观看黄网 | 97精品在线视频 | 女人高潮特级毛片 | 一区二区在线视频 | 欧美亚洲一区 | 黄在线免费观看 | 国产精品第一区 | 欧美一级片网站 | 男人天堂网在线 | 亚洲视频免费在线观看 | 国产高清一区 | 91精品国产色综合久久不卡98 | 欧美日韩综合网 | 国产综合视频在线观看 | 青青国产 | 免费黄色一级视频 | 91综合网 | av一区二区三区 | 欧美日韩中文字幕在线观看 | 一级黄色片免费观看 | 欧美手机在线 |