Search code examples
pythonpython-3.xpycharmzip

How to unzip files from an online source and then use them without saving on python


url = 'https://ihmecovid19storage.blob.core.windows.net/latest/ihme-covid19.zip'

from io import BytesIO
from zipfile import ZipFile
from urllib.request import urlopen
import pandas as pd

resp = urlopen(url)
zipfile = ZipFile(BytesIO(resp.read()))
print(zipfile.namelist()[-2])
print(zipfile.namelist()[-1])

a = zipfile.open(zipfile.namelist()[-2])
df2  = pd.DataFrame(a)
print(df2)

I'm stuck on reading part. When I convert the "a" to a dataframe, it gives me just one column. How do I get rid of this?


Solution

  • You can read the CSV with df2 = pd.read_csv(a)