Skip to content

Instantly share code, notes, and snippets.

@Jennyandhuang
Last active March 28, 2024 08:14
Show Gist options
  • Save Jennyandhuang/7e5415fd4f4135104c99075c40ab8efd to your computer and use it in GitHub Desktop.
Save Jennyandhuang/7e5415fd4f4135104c99075c40ab8efd to your computer and use it in GitHub Desktop.
Read a zip file directly in Python
#import packages
import pandas as pd
import os
import zipfile
#change directory
os.chdir('/Users/ChiHuang/Documents/python/python_files')
os.listdir()
#read zip file
zf=zipfile.ZipFile('411512_835452_compressed_2019-Nov.csv.zip','r')
#get the zip file name contained
zipfile.ZipFile.namelist(zf)
#choose the csv file to read under zip file
df = pd.read_csv(zf.open('2019-Nov.csv'))
@AZFARHAD24511
Copy link

what bout rar file is it possible to read rar file by this code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment