numpy loadtxt错误ValueError: Wrong number of columns at line ***
最近在爬b站视频评论
爬取之后存储在csv文件里面,但是用np.loadtxt读取的时候一直报错,最终发现问题在一个参数:comments上面:
这是报错数据:930行
这是读取代码:
data = np.loadtxt('./{}_reply.csv'.format(name), dtype='str,str,int',
encoding='utf-8', delimiter=" ,,, ",comments='$')
其中comments参数的作用在官方文档如此描述:
comments : str or sequence of str, optional The characters or list of characters used to indicate the start of a comment. None implies no comments. For backwards compatibility, byte strings will be decoded as 'latin1'. The default is '#'.
大意就是如果数据开头是#(默认是#) ,那就会跳过不读取该数据,所以解决方法也很简单,只要自己手动修改成另外一个自己数据里面没出现在开头的字符即可,我就是修改为$
本文来自博客园,作者:Hello418,转载请注明原文链接:https://www.cnblogs.com/janitor/p/16390832.html