Last active
March 28, 2024 08:14
-
-
Save Jennyandhuang/7e5415fd4f4135104c99075c40ab8efd to your computer and use it in GitHub Desktop.
Read a zip file directly in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what bout rar file is it possible to read rar file by this code?