简体   繁体   English

使用 pandas 读取 zip 文件

[英]Reading a zipfile with pandas

I am currently trying to read a csv file that I compressed into a zip file (this zip file only contains my csv).我目前正在尝试读取我压缩成 zip 文件的 csv 文件(此 zip 文件仅包含我的 csv)。 I tried to simply write pd.read_csv("trigramme_matrix.zip") (as suggested in the documentation) but this returns NotImplementedError: compression type 9 (deflate64) .我试图简单地编写pd.read_csv("trigramme_matrix.zip") (如文档中所建议的那样),但这会返回NotImplementedError: compression type 9 (deflate64) I then tried to solve my problem using the zipfile module with z = zipfile.ZipFile("trigramme_matrix.zip", "r") and then pd.read_csv(z.read("trigramme_matrix.csv")) but it keeps throwing the same error.然后我尝试使用带有z = zipfile.ZipFile("trigramme_matrix.zip", "r")然后pd.read_csv(z.read("trigramme_matrix.csv"))的 zipfile 模块解决我的问题,但它一直在抛出同样的错误。

I searched if I could get any insight on this error but the infos I got didn't help me much...我搜索了是否可以对这个错误有任何见解,但我得到的信息对我没有多大帮助......

I thank you by advance.我先谢谢你。

I assume you are using Windows like I am, please let me know if that is not the case.我假设您像我一样使用 Windows,如果不是这样,请告诉我。 Unzipping a type 9 Zip file is easy in Windows XP and higher because they have inbuilt support for Zip files.在 Windows XP 及更高版本中,解压缩类型 9 Zip 文件很容易,因为它们具有对 Zip 文件的内置支持。 I assume you are doing it before running the python code.我假设您在运行 python 代码之前正在执行此操作。 If you want to do this at runtime, the old post which we came across has code to unzip at runtime using the software 7Zip.如果您想在运行时执行此操作,我们遇到的旧帖子中有使用 7Zip 软件在运行时解压缩的代码。

Step 1: Extracting the csv from the type 9 Zip file步骤 1:从类型 9 Zip 文件中提取 csv

在此处输入图像描述

Windows Explorer will open the Zip file like any normal folder. Windows Explorer 将像打开任何普通文件夹一样打开 Zip 文件。 Have to copy the csv file in the zip file and paste it inside desired folder.必须复制 zip 文件中的 csv 文件并将其粘贴到所需的文件夹中。

Step 2: We can use Windows Explorer to zip the csv again, this time to a normal zip (Not type 9), which is the default used by Windows Explorer Step 2: We can use Windows Explorer to zip the csv again, this time to a normal zip (Not type 9), which is the default used by Windows Explorer

在此处输入图像描述

Step 3: If you want to use the command line for some reason, one way is to get some unzip software which works with the command line, for example http://stahlworks.com/dev/unzip.exe第 3 步:如果您出于某种原因想使用命令行,一种方法是获取一些可与命令行一起使用的解压缩软件,例如http://stahlworks.com/dev/unzip.exe

Please make sure you scan it using your antivirus请确保您使用防病毒软件对其进行扫描

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM