I have a zipped file which contains a csv, compressed with xz. I want to unzip it into the memory, and read wit pandas' read_csv
method.
Pandas knows xz compression
data = pd.read_csv(filepath_or_buffer=file, index_col=0, compression='xz', engine='c')
I know how to unzip a file
input_zip=ZipFile(zip_file)
input_zip=ZipFile(zip_file)
file in input_zip.namelist():
But I do not know how to glue the two code together
Solution:
input_zip=ZipFile(input_zip)
for filename in input_zip.namelist():
bytes = input_zip.read(filename)
data = pd.read_csv(io.BytesIO(bytes), index_col=0, compression='xz', engine='c')