ValueError: could not convert string to float

ValueError: could not convert string to float

在使用jupyter notebook下,操作csv文件的时候报错
ValueError: could not convert string to float: ‘英语’
先看一下我们读取的csv是这个
ValueError: could not convert string to float_第1张图片
错误代码如下:
ValueError: could not convert string to float_第2张图片
琢磨的有点久,我们用help(np.savetxt)查看函数使用规则
ValueError: could not convert string to float_第3张图片
最后发现是这个地方出了问题dtype=np.int
在这里插入图片描述
ValueError: could not convert string to float_第4张图片
读取的文件中有字符串,不能转换为int类型。

这个时候我们可以使用skiprows=1
意思为,跳过第一行,开始读取。
更改后代码如下:
ValueError: could not convert string to float_第5张图片
最后报错就解决了。
一位大数据技术的萌新,可能有些地方写的不是特别好,还请大家指出斧正。

你可能感兴趣的:(报错解决,python)