【发布时间】:2020-07-12 15:25:22
【问题描述】:
def loadCsv(filename):
lines = csv.reader(open('diabetes.csv'))
dataset = list(lines)
for i in range(len(dataset)):
dataset[i] = [float(x) for x in dataset[i]
return dataset
您好,我正在尝试实现 Naive-Bayes,但即使我已手动将每列的类型更改为浮动,它也会给我这个错误。 它仍然给我错误。 以上是要转换的函数。
【问题讨论】:
-
没有关于
dataset[i]内容的任何信息,我们无法为您提供帮助。将dataset[i]中的内容打印出来,查看是否有不能转float的项目(如字母串) -
df = pd.read_csv('diabetes.csv') df.dtypes Pregnancy int64 Glucose int64 BloodPressure int64 SkinThickness int64 Insulin int64 BMI float64 DiabetesPedigreeFunction float64 Age int64 结果 int64 dtype: object
-
没有字符串,它只取第一列的名称并表示它不能转换为浮点数。这是 pima-diabetes 数据集。怀孕是第一列的名称
标签: python-3.x data-science naivebayes valueerror