我试图使用下面的代码重现书中的房屋数据集/代码,但不知何故,我得到了最后显示的错误
In [32]:import osimport tarfilefrom six.moves import urllibIn [37]:DOWNLOAD_ROOT = "https://raw.githubusercontent.com/ageron/handson-ml/master/"HOUSING_PATH = "/home/isaac/Fundamentals of Data Science Certificate/3253 - Machine Learning/Code from book"HOUSING_URL = DOWNLOAD_ROOT + HOUSING_PATH + "/housing.tgz"In [41]:def fetch_housing_data(housing_url=HOUSING_URL, housing_path=HOUSING_PATH): if not os.path.isdir(housing_path): os.makedirs(housing_path) tgz_path = os.path.join(housing_path, "housing.tgz") urllib.request.urlretrieve(housing_url, tgz_path) housing_tgz = tarfile.open(tgz_path) housing_tgz.extractall(path=housing_path) housing_tgz.close()In [42]:import pandas as pddef load_housing_data(housing_path=HOUSING_PATH): csv_path = os.path.join(housing_path, "housing.csv") return pd.read_csv(csv_path)In [43]:housing = load_housing_data()housing.head
FileNotFoundError: File b'/home/isaac/Fundamentals of Data Science Certificate/3253 - Machine Learning/Code from book/housing.csv' does not exist
我该如何解决这个问题?
回答:
你没有在任何地方调用fetch_housing_data
来创建文件'housing.tgz'
(你还假设文件'housing.tgz'
包含了文件"housing.csv"
的压缩版本)