我正在使用conda
python
2.7
python --version
Python 2.7.12 :: Anaconda 2.4.1 (x86_64)
我有fallowing方法来读取大型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代码成功地读取该文件:
输入zip文件已损坏。从try to use zip repairing tools的源获取此文件的正确副本,然后再将其传递给pandas。
相关问题 更多 >
编程相关推荐