I am working to load data into pandas dataframe from downloaded zip file using REST API. I am able to load the file into dataframe if I know the name of the file using the following code:
z=zipfile.ZipFile(io.BytesIO(request_download.content))
df=pd.read_csv(z.open('Test1-RB.csv'))
print(df)
Is there a way that I can load the data into the dataframe without specifying the filename? I am trying to do something like this:
z=zipfile.ZipFile(io.BytesIO(request_download.content))
df=pd.read_csv(z,compression="zip")
print(df)
but I am getting following error on trying to do that
Invalid file path or buffer object type: <class 'zipfile.ZipFile'>
I was able to get around this through the following code. I am not entering any filename on this now.
z=zipfile.ZipFile(io.BytesIO(request_download.content))
dfs=[]
for file in z.namelist():
dfs.append(pd.read_csv(z.open(file),sep=';'))
df1 = pd.concat(dfs)
print(df1)