'Read separately zipped csv file (.zip .z01 etc) over Python zipfile library
How could we read csv file which is zipped into multiple files?
Due to the 4 GB limit of FAT storage format, I have complied csv file into multiple zip files like test.zip
and test.z01
.
I found the library zipfile
which can read csv file in the "single" zipped file. But I have no idea with reading a csv file in "separately" zipped file.
For example: Reading csv zipped files in python provide how to read csv file in one zipped file.
import pandas as pd
import zipfile
zf = zipfile.ZipFile('C:/Users/Desktop/THEZIPFILE.zip')
df = pd.read_csv(zf.open('intfile.csv'))
In summary, my question is that how can we read both test.zip
and test.z01
at the same time and access to the csv file?
Solution 1:[1]
I solved this problem in a roundabout way by explicitly making two csv file into completely different two zipped file which have similar number of columns and combline them into one file.
import pandas as pd
import zipfile
zf1 = zipfile.ZipFile('C:/Users/Desktop/THEZIPFILE1.zip')
df1 = pd.read_csv(zf1.open('intfile.csv'))
zf2 = zipfile.ZipFile('C:/Users/Desktop/THEZIPFILE2.zip')
df2 = pd.read_csv(zf2.open('intfile.csv'))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |