Pandas: Multiple CSVs in one Zip file

31 views
Skip to first unread message

Abdur-Rahmaan Janhangeer

unread,
Aug 26, 2021, 3:10:06 AM8/26/21
to
Greetings,

Cannot read one file in a zip file if the zip file contains multiple files.

This example does not work https://www.py4u.net/discuss/203494 as Pandas
shows a ValueError: Multiple files found in ZIP file. Only one file per ZIP.

If the Zip file has one file, fine else i cannot find a way. Thanks

Kind Regards,

Abdur-Rahmaan Janhangeer
about <https://compileralchemy.github.io/> | blog
<https://www.pythonkitchen.com>
github <https://github.com/Abdur-RahmaanJ>
Mauritius

Peter Otten

unread,
Aug 26, 2021, 4:04:30 AM8/26/21
to
On 26/08/2021 09:09, Abdur-Rahmaan Janhangeer wrote:

> Cannot read one file in a zip file if the zip file contains multiple files.
>
> This example does not work https://www.py4u.net/discuss/203494 as Pandas
> shows a ValueError: Multiple files found in ZIP file. Only one file per ZIP.
>
> If the Zip file has one file, fine else i cannot find a way. Thanks

You may have introduced an error when you translated the snippet to your
use case. What went wrong is hard to guess unless you provide the exact
failing code.

Pandas can read a single zipped file out of the box and the accepted
answer in your indirect link to

https://stackoverflow.com/questions/61971040/python-extract-csv-files-from-multiple-zip-files-and-combine-the-data

shows how to deal with zip files containing multiple files.

Peter J. Holzer

unread,
Aug 26, 2021, 6:00:04 AM8/26/21
to
On 2021-08-26 11:09:21 +0400, Abdur-Rahmaan Janhangeer wrote:
> Cannot read one file in a zip file if the zip file contains multiple files.
>
> This example does not work https://www.py4u.net/discuss/203494 as Pandas
> shows a ValueError: Multiple files found in ZIP file. Only one file per ZIP.
>
> If the Zip file has one file, fine else i cannot find a way. Thanks

Is it possible that you are trying to treat the zip file as a gzip file?
Those are different file formats with different purposes (archive vs.
stream), but they use the same compression algorithm, and the gzip tool
(and - I presume - also the gzip library) can read a zip file with a
single member. The error message would match that.

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | h...@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
signature.asc
Reply all
Reply to author
Forward
0 new messages