Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

797
Views
Pandas. How to read Excel file from ZIP archive

I have .zip archive with filename.xlsx inside it and I want to parse Excel sheet line by line.

How to proper pass filename into pandas.read_excel in this case?

I tried:

import zipfile
import pandas
myzip=zipfile.ZipFile(filename.zip)
for fname in myzip.namelist():
    with myzip.open(fname) as from_archive:
        with pandas.read_excel(from_archive) as fin:
            for line in fin:
            ....

but it doesn't seem to work, and the result was:

AttributeError: __exit__
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You can extract your zip-file into a variable in memory and parse it using io.BytesIO:

import io
from zipfile import ZipFile
import pandas as pd


def read_zip(zip_fn, extract_fn=None):
    zf = ZipFile(zip_fn)
    if extract_fn:
        return zf.read(extract_fn)
    else:
        return {name:zf.read(name) for name in zf.namelist()}

Usage:

df = pd.read_excel(io.BytesIO(read_zip(r'C:\download\test.xlsx.zip', 'test.xlsx')))

Alternatively you can extract files from the zip-file to disk and parse them as a regular files.

PS there are tons of examples on StackOverflow, showing how to explode zip-file...

over 4 years ago · Santiago Trujillo Report

0

Using zipfile

import zipfile

archive = zipfile.ZipFile('filename.zip', 'r')
xlfile = archive.open('filename.xlsx')
df = pd.read_excel(xlfile)
over 4 years ago · Santiago Trujillo Report

0

Simple way is:

df = pd.read_csv('path to file', compression='zip').

if u need u can to add extra atr: encoding = 'windows-1251' and sep = ''

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!