怎么解决could not convert string to float问题?

在jupyter里读取csv文件做决策树的分类器

导入文件,划分测试集,训练集后

filename="D:/学生/student-por.csv"
file=pd.read_csv(filename,encoding="GB2312")

X=file.drop(columns=['G3'])
y=file['G3']
x_train,x_test,y_train,y_test=train_test_split(X,y,test_size=0.2)

进行训练后

dt=DecisionTreeClassifier().fit(x_train,y_train)

就出现了 could not convert string to float: 'MS'的错误

csv文件内原是左边形式,后改成右边形式,难道是这个原因

怎么解决could not convert string to float问题?_第1张图片怎么解决could not convert string to float问题?_第2张图片 

 但后来导入左边形式会出现表头与数据错位现象,故继续使用右边形式,但不知怎么改正could not convert string to float: 'MS'的错误啊,求大佬指点

        后来将数据里非数字的内容删除后可以正常运行了,但这分类器只能分数字嘛,这不合理啊

你可能感兴趣的:(决策树,机器学习,python)