Last active
June 5, 2023 22:06
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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