Discuss@GL4L

Python- How do we read a zip file directly?


#1

We can use “zipfile” module to read ZIP archive files.

import pandas as pd
import zipfile

zf = zipfile.ZipFile(‘file-path’) # having sample.csv zipped file.
df = pd.read_csv(zf.open(‘sample.csv’))

Here, please follow the below link for more info:
https://pymotw.com/2/zipfile/

OR

You can now directly read the csv file inside zip folder (given that there is only one csv file present in the folder). Below is the command:

df=pd.read_csv(“folder_name.zip”)