Created
September 14, 2021 09:01
-
-
Save ThePyProgrammer/5c3c5916b97acd3acdfb2d134fb5ef18 to your computer and use it in GitHub Desktop.
A utitlity function list that can allow simpler code.
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 requests | |
import pandas as pd | |
import re | |
from io import StringIO | |
def read_csv(loc, *args, **kwargs): | |
if re.search(r"[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)", loc): | |
return read_csv(requests.get(loc, allow_redirects=True).content, *args, **kwargs) | |
loc = loc.strip("\n") | |
if re.search(r"[\n:<>\"/\|?*]", loc): | |
return pd.read_csv(StringIO(loc), *args, **kwargs) | |
else: | |
return pd.read_csv(loc, *args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment