Skip to content

Instantly share code, notes, and snippets.

@TanAlex
Created February 15, 2023 06:58
Show Gist options
  • Save TanAlex/93017e1ca3b7e627af93bfd91e49a07d to your computer and use it in GitHub Desktop.
Save TanAlex/93017e1ca3b7e627af93bfd91e49a07d to your computer and use it in GitHub Desktop.
[DS Python Snippets] DS Python Snippets #DataScience #Python
from pathlib import Path
import pandas as pd
import tarfile
import urllib.request
def load_housing_data():
tarball_path = Path("datasets/housing.tgz")
if not tarball_path.is_file():
Path("datasets").mkdir(parents=True, exist_ok=True)
url = "https://github.com/ageron/data/raw/main/housing.tgz"
urllib.request.urlretrieve(url, tarball_path)
with tarfile.open(tarball_path) as housing_tarball:
housing_tarball.extractall(path="datasets")
return pd.read_csv(Path("datasets/housing/housing.csv"))
housing = load_housing_data()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment