【发布时间】:2020-05-26 15:36:31
【问题描述】:
我想从 .csv 文件中读取数据行,每当我运行我的代码时,它都会弹出这个错误。我不知道如何解决这个问题。我查了一些类似的帖子,但仍然无法解决。
这是我的代码:
def getThreshold(dataSet, Attributes, isNumeric):
'''
Calculates median threshold from train dataset
'''
thresholds = []
for x in Attributes:
indx = Attributes.index(x)
numeric = isNumeric[indx]
if numeric:
listAtt = []
for row in dataSet:
listAtt.append(float(row[indx]))
# calculate median a numeric attribute column
median = statistics.median(listAtt)
thresholds.append(median)
return thresholds
这是我的示例数据,(不带引号)
41,management,single,secondary,no,764,no,no,cellular,12,jun,230,2,-1,0,unknown,no
39,blue-collar,married,secondary,no,49,yes,no,cellular,14,may,566,1,370,2,failure,no
60,retired,married,primary,no,0,no,no,telephone,30,jul,130,3,-1,0,unknown,no
31,entrepreneur,single,tertiary,no,247,yes,yes,unknown,2,jun,273,1,-1,0,unknown,no
发现问题的第一列是年龄,被标识为字符串。是csv文件的问题还是代码的问题?
【问题讨论】:
-
请将此减少并增强为预期的MRE。