0

我尝试通过 CSV 文件学习回归,但出现以下错误:

> ValueError                                Traceback (most recent call
> last) <ipython-input-36-ca92008c8d98> in <module>
>       7     for line in f:
>       8         line=line.strip().split(',')
> ----> 9         data['Username'].append(float(line[0]))
>      10 
>      11 
> 
> ValueError: could not convert string to float:

我的代码是

for header in ["Username","Identifier","First name","Last name"]:
    data[header]=[]

with open('username.csv','r') as f:
    next(f)

    for line in f:
        line=line.strip().split(',')
        data['Username'].append(float(line[0]))
  

我的 CSV 文件看起来像这样

Username, Identifier,First name,Last name
112,9012,2,3.223 
123,2070,0.8276,3.098
876,4081,567,4.34
56,9346,789,3.78
5,507,9678,2.789

   
4

0 回答 0