Python Pandas read_csv报错
为实现文本去重(将前面采集的数据进行两两对比删除重复),写了以下代码。
#-*- coding: utf-8 -*-
import pandas as pd
inputfile = 'e:/data/H_KJ300F-JAC2101W.txt' #评论文件
outputfile = 'e:/data/H_KJ300F-JAC2101W_process_1.txt' #评论处理后保存路径
data = pd.read_csv(inputfile, encoding = 'utf-8', header = None)
l1 = len(data)
data = pd.DataFrame(data[0].unique())
l2 = len(data)
data.to_csv(outputfile, index = False, header = False, encoding = 'utf-8')
print(u'删除了%s条评论。' %(l1 - l2))
报错:
Traceback (most recent call last): File "<stdin>", line 1, in <module> return _read(filepath_or_buffer, kwds) File "D:\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 401, in _read data = parser.read() File "D:\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 939, in read ret = self._engine.read(nrows) File "D:\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 1508, in read data = self._reader.read(nrows) File "pandas\parser.pyx", line 848, in pandas.parser.TextReader.read (pandas\parser.c:10415) File "pandas\parser.pyx", line 870, in pandas.parser.TextReader._read_low_memory (pandas\parser.c:10691) File "pandas\parser.pyx", line 924, in pandas.parser.TextReader._read_rows (pandas\parser.c:11437) File "pandas\parser.pyx", line 911, in pandas.parser.TextReader._tokenize_rows (pandas\parser.c:11308) File "pandas\parser.pyx", line 2024, in pandas.parser.raise_parser_error (pandas\parser.c:27037)pandas.io.common.CParserError: Error tokenizing data. C error: Expected 1 fields in line 360, saw 2>>> data =pd.read_csv(inputfile,encoding ='utf-8',header = None) data = self._reader.read(nrows) File "pandas\parser.pyx", line 848, in pandas.parser.TextReader.read (pandas\parser.c:10415)>>> File "pandas\parser.pyx", line 911, in pandas.parser.TextReader._tokenize_rows (pandas\parser.c:11308) File "pandas\parser.pyx", line 2024, in pandas.parser.raise_parser_error (pandas\parser.c:27037)pandas.io.common.CParserError: Error tokenizing data. C error: Expected 1 fields in line 361, saw 2 File "pandas\parser.pyx", line 870, in pandas.parser.TextReader._read_low_memory (pandas\parser.c:10691) File "pandas\parser.pyx", line 924, in pandas.parser.TextReader._read_rows (pandas\parser.c:11437) ret = self._engine.read(nrows) File "D:\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 1508, in read data = parser.read() File "D:\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 939, in read return _read(filepath_or_buffer, kwds) File "D:\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 401, in _read File "D:\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 646, in parser_fTraceback (most recent call last): File "<stdin>", line 1, in <module>
解决:把整个文件里面的半角","换成全角",“
原因:没有设定分隔符的情况下,默认使用","作为分隔条符。
Python Pandas read_csv报错的更多相关文章
- pandas.read_csv() 报错 OSError: Initializing from file failed,报错原因分析和解决方法
今天调用pandas读取csv文件时,突然报错“ OSError: Initializing from file failed ”,我是有点奇怪的,以前用的好好的,read_csv(path)方法不是 ...
- read_csv报错Initializing from file failed
Python版本:Python 3.6 pandas.read_csv() 报错 OSError: Initializing from file failed,一般由两种情况引起:一种是函数参数为路径 ...
- 【python】python读取文件报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 2: illegal multibyte sequence
python读取文件报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 2: illegal multibyte ...
- 【python】python安装tensorflow报错:python No matching distribution found for tensorflow==1.12.0
python安装tensorflow报错:python No matching distribution found for tensorflow==1.12.0 python版本是3.7.2 要安装 ...
- mac下python环境pip报错[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) 的解决方法
1.mac下python环境pip报错: issuserdeMacBook-Pro:~ issuser$ pip install pyinstallerCollecting pyinstaller ...
- Django中修改DATABASES后,执行python manage.py ****报错!UnicodeEncodeError
Django中修改DATABASES后,执行python manage.py ****报错!UnicodeEncodeError: 'latin-1' codec can't encode chara ...
- python 安装模块报错 response.py", line 302, in _error_catcher
python 安装模块报错 Exception:Traceback (most recent call last): File "/usr/share/python-wheels/urlli ...
- 【原创】大叔经验分享(11)python引入模块报错ImportError: No module named pandas numpy
python应用通常需要一些库,比如numpy.pandas等,安装也很简单,直接通过pip # pip install numpyRequirement already satisfied: num ...
- python读取文件报错:pandas.errors.ParserError: iterator should return strings, not bytes (did you open the file in text mode?)
python 读取csv文件报错问题 import csv with open('E:/Selenium2script/DDT模块/test.csv','rb') as f: readers = cs ...
随机推荐
- 前端aes解密实战小结
很多人对于AES加密并不是很了解,导致互相之间进行加密解密困难. 本文用简单的方式来介绍AES在使用上需要的知识,而不涉及内部算法.最后给出例子来帮助理解AES加密解密的使用方法. AES的麻烦 相比 ...
- BZOJ3236:[AHOI2013]作业(莫队,分块)
Description Input Output Sample Input 3 4 1 2 2 1 2 1 3 1 2 1 1 1 3 1 3 2 3 2 3 Sample Output 2 2 1 ...
- Invoking "cmake" failed报错处理
运行$ pip install -U rosdep rosinstall_generator wstool rosinstall six vcstools运行完成后再重新编译
- linux内核中socket的创建过程源码分析(详细分析)
1三个相关数据结构. 关于socket的创建,首先需要分析socket这个结构体,这是整个的核心. 104 struct socket { 105 socket_state ...
- Python2.7-fileinput
fileinput 模块,对输入的文件流进行迭代操作,可以说是对 open() 的一个扩展,它可以直接修改文件,也可以对他们进行备份 模块方法: fileinput.input([files[, in ...
- JAVA框架 Spring 引入多个配置文件
1.如果配置文件比较长,可以分多个配置文件.有两种方式: 1)在主配置文件加标签<import/> <import resource="jd/com/other/appli ...
- cloudstack secondary vm starting
等1个小时,差不多可以进入虚拟机,看日志/var/log/cloud.log
- Beautifulsoap - request 网络爬虫 (转)
http://www.cnblogs.com/jiayongji/p/7118939.html (转) python爬虫系列(2)—— requests和BeautifulSoup库的基本用法
- currentBackgroundImage:获取按钮背景图片
NSData *imagedata1=UIImagePNGRepresentation(btn.currentBackgroundImage);//按钮背景图片转NSData NSData *imag ...
- Android Environment.getExternalStorageDirectory() 获取的是内部存储还是外部存储? - z
这几天在做Android应用的远程更新功能,将下载的更新包放在移动设备上指定的目录.用的是 Environment.getExternalStorageDirectory() 这个方法,然后在获取的 ...