Python: 数据令授权错误。 C 错误:呼叫 read /nbytes/ 源无法输入文件。 nzip

我用
conda


python


2.7



python --version
Python 2.7.12 :: Anaconda 2.4.1 /x86_64/


我有一个读取大文件的存款方式 gzip:


df = pd.read_csv/os.path.join/filePath, fileName/,
sep='|', compression = 'gzip', dtype='unicode', error_bad_lines=False/


但是当我读取文件时,我会收到以下错误:


pandas.parser.CParserError: Error tokenizing data. C error: Calling read/nbytes/ on source failed. Try engine='python'.
Segmentation fault: 11


我阅读了所有现有答案,但在大多数这些问题中存在错误,例如附加列。 我已经使用该选项支付了这一点
error_bad_lines=False

.

我的选择是什么?

当我尝试解压缩文件时,我发现了一些有趣的东西:


gunzip -k myfile.txt.gz 
gunzip: myfile.txt.gz: unexpected end of file
gunzip: myfile.txt.gz: uncompress failed
已邀请:

知食

赞同来自:

事实上,我没有找到解决方案 python, 但是使用工具
unix

我设法找到一个解决方案:

首先我使用
zless myfile.txt.gz > uncompressedMyfile.txt

, 然后工具
sed

, 要删除最后一个字符串,因为我清楚地看到了最后一条线损坏了。


sed '$d' uncompressedMyfile.txt


我再次解压缩了这个文件
gzip -k uncompressedMyfile.txt


我能够用以下代码成功读取该文件。 python:


try:
df = pd.read_csv/os.path.join/filePath, fileName/,
sep='|', compression = 'gzip', dtype='unicode', error_bad_lines=False/
except CParserError:
print "Something wrong the file"
return df

莫问

赞同来自:

输入文件。 zip 损坏的。 从源中获取此文件的正确副本尝试使用 zip 通过它之前修复工具 pandas.

裸奔

赞同来自:

有时如果文件已打开,则会出现错误。 尝试关闭文件并再次启动。

裸奔

赞同来自:

最有可能,你设置的道路实际上是这样的
folder

反而
file

, 应该阅读哪个。


Pandas.read_csv

无法读取文件夹并需要显式兼容的文件名。

要回复问题请先登录注册