首页 > 解决方案 > 写入 CSV 给出,错误:无法将字符串转换为浮点数

问题描述

我在将 CSV 文件添加到 Python 时遇到问题,我编写了这个程序:

import csv

file=r'C:Users\kloner\Desktop\Stage\partactions.csv'
reader=csv.reader(open(file, encoding = "ISO-8859-1"))

liste=[]

for row in reader:
    liste.append(row)

liste.pop(0)
M=matrix(RDF,liste)
print(M)

但它给了我以下错误:

错误:无法将字符串转换为浮点数

图片

标签: pythoncsvsage

解决方案


我认为矩阵是 np.matrix 并且有些代码很奇怪。

也许它应该是这样的。

import csv
from numpy import matrix

file=r'C:Users\kloner\Desktop\Stage\partactions.csv'
reader=csv.reader(open(file, encoding = "ISO-8859-1"))

liste=[]
for row in reader:
    liste.append(row)
liste.pop(0)
M=matrix(liste)
print(M)

推荐阅读