1

I want to get access to a zipped excel sheet online using python without downloading it to my PC. The link is as follow https://www.richmondfed.org/-/media/richmondfedorg/research/regional_economy/surveys_of_business_conditions/manufacturing/zipfile/mfg_historicaldata.zip, which points to a zipped excel. Does anyone know how to use python to deal with it? For example, I want to print the first row of the excel without unzipping and saving the file directly in my PC.

Downloading and unzipping a .zip file without writing to disk

I have found a similar question below, however, I cannot use this code to read the excel file.

Demebleeee
  • 21
  • 2
  • 1
    Possible duplicate of [Downloading and unzipping a .zip file without writing to disk](https://stackoverflow.com/questions/5710867/downloading-and-unzipping-a-zip-file-without-writing-to-disk) – Kushan Gunasekera Jun 27 '19 at 04:17

1 Answers1

2

You can use pandas to read the excel file.

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

resp = urlopen("https://www.richmondfed.org/-/media/richmondfedorg/research/regional_economy/surveys_of_business_conditions/manufacturing/zipfile/mfg_historicaldata.zip")
zipfile = ZipFile(BytesIO(resp.read()))
extracted_file = zipfile.open(zipfile.namelist()[0])
print(pd.read_excel(extracted_file))
Kartikeya Sharma
  • 1,335
  • 1
  • 10
  • 22