def fetch_housing_data(housing_url=HOUSING_URL, housing_path=GlobalParam.get_ml_ch2_housing_data()): if not os.path.isdir(housing_path): os.makedirs(housing_path) print(GlobalParam.get_ml_ch2_housing_data()) tgz_path = os.path.join(housing_path, "housing.tgz") request.urlretrieve(housing_url, tgz_path) housing_tgz = tarfile.open(tgz_path) housing_tgz.extractall(path=housing_path) housing_tgz.close()
def load_housing_data(housing_path=GlobalParam.get_ml_ch2_housing_data()): csv_path = os.path.join(housing_path, "housing.csv") return pd.read_csv(csv_path)