Skip to content

Instantly share code, notes, and snippets.

@andrewdoss-bit
Last active August 12, 2021 19:15
Show Gist options
  • Save andrewdoss-bit/36017ad2e658c0d1cee3a2b4609ad0d1 to your computer and use it in GitHub Desktop.
Save andrewdoss-bit/36017ad2e658c0d1cee3a2b4609ad0d1 to your computer and use it in GitHub Desktop.
Extract
"""Provides extraction functions.
Currently only supports GET from URL or local file.
"""
import io
import pandas as pd
import requests
def csv_from_get_request(url):
"""Extracts a data text string accessible with a GET request.
Parameters
----------
url : str
URL for the extraction endpoint, including any query string
Returns
----------
DataFrame
"""
r = requests.get(url, timeout=5)
data = r.content.decode('utf-8')
df = pd.read_csv(io.StringIO(data), low_memory=False)
return df
def csv_from_local(path):
"""Extracts a csv from local filesystem.
Parameters
----------
path : str
Returns
----------
DataFrame
"""
return pd.read_csv(path, low_memory=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment