I have a zip directory similar to this one:
folder_to_zip
- file_1.csv
- folder_1.zip
1. file_2.csv
2. file_3.csv
3. folder_2.zip
**.**file_4.csv
**.**file_5.csv
**.** file_6.csv
-file_7.csv
and I would like to "put" each csv file in a different pandas dataframe
The reason I want to do that is because I do not want this project to be too "heavy" ( the zip_folder is just 639MB insted of 7.66 GB)
based on these questions (Python: Open file in zip without temporarily extracting it, Python py7zr can't list files in archive - how to read 7z archive without extracting it) I tried something like this:
from py7zr import SevenZipFile as szf
import os
import pandas as pd
def unzip_(folder_to_zip):
dfs= []
if not folder_to_zip.endswith('.csv'):
dfs.append(pd.read_csv(folder_to_zip))
else:
with szf(folder_to_zip, 'r') as z:
for f in z.getnames():
dfs += unzip_(f)
return dfs