Skip to content

Instantly share code, notes, and snippets.

@crspiccin
Last active June 5, 2023 22:06
Show Gist options
  • Save crspiccin/aca84613eb31620950140b0a1d9d8f5a to your computer and use it in GitHub Desktop.
Save crspiccin/aca84613eb31620950140b0a1d9d8f5a to your computer and use it in GitHub Desktop.
Pandas: read a csv file inside a zip located on a remote path
import zipfile
import io
import requests
def load_dataframe_from_http_zip_csv_file(endpoint, csv_filename, engine='python', encoding='ISO-8859-1', delimiter=';', skiprows=0, index_col=None):
response = requests.get(endpoint)
zip_data = zipfile.ZipFile(io.BytesIO(response.content))
zip_data.extract(csv_filename, path='extracted_directory')
df = pd.read_csv(f'extracted_directory/{csv_filename}', encoding=encoding, delimiter=delimiter, engine=engine, skiprows=skiprows, index_col=index_col)
return df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment