Created
February 15, 2023 06:58
-
-
Save TanAlex/93017e1ca3b7e627af93bfd91e49a07d to your computer and use it in GitHub Desktop.
[DS Python Snippets] DS Python Snippets #DataScience #Python
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
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