ValueError:无法将字符串转换为float:

时间:2017-04-21 08:12:15

标签: python

以下是我的代码,数据集是titanic dataset

with open('titanic.csv','rb') as csvfile:
    titanic_reader = csv.reader(csvfile,delimiter=',',quotechar='"')
    row = titanic_reader.next()
    feature_names=np.array(row)
    titanic_X,titanic_y = [],[]
    for row in titanic_reader:
        titanic_X.append(row)
        titanic_y.append(row[2])
    titanic_X = np.array(titanic_X)
    titanic_y = np.array(titanic_y)

titanic_X = titanic_X[:,[1,4,10]]
feature_names = feature_names[[1,4,10]]
ages = titanic_X[:, 1]
mean_age = np.mean(titanic_X[ages != 'NA',1].astype(np.float))

ValueError Traceback(最近一次调用最后一次)  in()       1 mean_age = np.mean(titanic_X[ages != 'NA', ----> 2 1].astype(np.float))

ValueError:无法将字符串转换为float:

但除了数字和NA之外什么也没有,为什么它不能将字符串转换为浮点数?

0 个答案:

没有答案