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

ValueError:無(wú)法將字符串轉(zhuǎn)換為浮點(diǎn)數(shù):id

ValueError: could not convert string to float: id(ValueError:無(wú)法將字符串轉(zhuǎn)換為浮點(diǎn)數(shù):id)
本文介紹了ValueError:無(wú)法將字符串轉(zhuǎn)換為浮點(diǎn)數(shù):id的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我正在運(yùn)行以下 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]

但是我得到了如下錯(cuò)誤:

However I got the errors like:

ValueError: could not convert string to float: id

我對(duì)此感到困惑.當(dāng)我在交互部分中僅對(duì)一行嘗試此操作時(shí),而不是使用腳本進(jìn)行循環(huán):

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

效果很好.

誰(shuí)能解釋一下這個(gè)?謝謝.

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

推薦答案

顯然您的某些行沒(méi)有有效的浮點(diǎn)數(shù)據(jù),特別是某些行包含無(wú)法轉(zhuǎn)換為的文本 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.

當(dāng)您在交互式提示中嘗試時(shí),您只嘗試第一行,因此最好的方法是打印出現(xiàn)此錯(cuò)誤的行,您會(huì)知道錯(cuò)誤的行,例如

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]

這篇關(guān)于ValueError:無(wú)法將字符串轉(zhuǎn)換為浮點(diǎn)數(shù):id的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Python 3 Float Decimal Points/Precision(Python 3 浮點(diǎn)小數(shù)點(diǎn)/精度)
Converting Float to Dollars and Cents(將浮點(diǎn)數(shù)轉(zhuǎn)換為美元和美分)
What are some possible calculations with numpy or scipy that can return a NaN?(numpy 或 scipy 有哪些可能的計(jì)算可以返回 NaN?)
Python float to ratio(Python浮動(dòng)比率)
How to manage division of huge numbers in Python?(如何在 Python 中管理大量數(shù)字的除法?)
mean from pandas and numpy differ(pandas 和 numpy 的意思不同)
主站蜘蛛池模板: 一区二区三区中文字幕 | 亚洲视频在线一区 | 欧美日韩中文字幕 | 久久中文高清 | 91av在线电影 | 日本精品国产 | 狠狠亚洲 | 日本特黄a级高清免费大片 国产精品久久性 | 国产伦精品一区二区三区视频金莲 | 亚洲综合一区二区三区 | 亚洲精品一区av在线播放 | 国产成人精品一区 | av一区二区三区四区 | 久久国产精品精品 | 日韩精品在线免费 | 成人在线不卡 | 欧美一区不卡 | 艹逼网 | 精品久久一区 | 免费1区2区3区 | 中文字幕视频免费 | 国产一级大片 | 久久精品青青大伊人av | 日韩午夜激情 | 国产高潮好爽受不了了夜色 | 国产精品久久久久久av公交车 | 高清国产一区二区 | 日韩欧美一区二区三区免费观看 | 美国十次成人欧美色导视频 | 国产高清一区二区三区 | 国产二区av | 91欧美激情一区二区三区成人 | 欧美日韩成人影院 | 中文字幕日韩一区 | 日韩精品一区二区三区在线播放 | 91精品国产91久久综合桃花 | 韩日一区二区 | 综合亚洲视频 | 五月婷婷 六月丁香 | 日本欧美视频 | 一级看片免费视频 |