日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python导入csv报错_Python Pandas read_csv报错

發(fā)布時(shí)間:2024/1/23 python 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python导入csv报错_Python Pandas read_csv报错 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

為實(shí)現(xiàn)文本去重(將前面采集的數(shù)據(jù)進(jìn)行兩兩對(duì)比刪除重復(fù)),寫了以下代碼。

#-*- coding: utf-8 -*-

import pandas as pd

inputfile = 'e:/data/H_KJ300F-JAC2101W.txt' #評(píng)論文件

outputfile = 'e:/data/H_KJ300F-JAC2101W_process_1.txt' #評(píng)論處理后保存路徑

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條評(píng)論。' %(l1 - l2))

報(bào)錯(cuò):

Traceback (most recent call last): File "", line 1, in 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 "", line 1, in

解決:把整個(gè)文件里面的半角","換成全角",“

原因:沒有設(shè)定分隔符的情況下,默認(rèn)使用","作為分隔條符。

總結(jié)

以上是生活随笔為你收集整理的python导入csv报错_Python Pandas read_csv报错的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。