Reading Csv Files From Zip Archive With Python-3.x
I have a zipped archive that contains several csv files. For instance, assume myarchive.zip contains myfile1.csv, myfile2.csv, myfile3.csv In python 2.7 I was able to load iterati
Solution 1:
Strange indeed, since the only mode you can specify is r/w
(character modes).
Here's a workaround; read the file using file.read
, load the data into a StringIO
buffer, and pass that to read_csv
.
from io importStringIO
with zipfile.ZipFile(myarchive.zip, 'r') aszippedyear:
for filename in ['myfile1.csv', 'myfile2.csv', 'myfile3.csv']:
with zippedyear.open(filename) asf:
mydf = pd.read_csv(io.StringIO(f.read()))
Post a Comment for "Reading Csv Files From Zip Archive With Python-3.x"