I'm targeting a *_foo_*.csv
file in the hirerachy below :
NB : the 2nd.zip
is optional (i.e, the files of the 2nd.zip
could be directly zipped in the 1st.zip
.
My code below returns always None
:
from zipfile import ZipFile
import pandas as pd
fp = r'C:\Users\rendezvous\Downloads\1st.zip'
def zip_to_df(fp):
zip_file = ZipFile(fp)
for name in zip_file.namelist():
if name.endswith('.csv'):
df = pd.read_csv(zip_file.open(name))
return df
elif name.endswith('.zip'):
zip_to_df(zip_file.open(name))
df = zip_to_df(fp)
Can you explain why, please ? I can't figure it out.