作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用下面的代码重新创建书中的住房数据集/代码。由于某种原因,我得到了最后一直显示的错误
In [32]:
import os
import tarfile
from six.moves import urllib
In [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 pd
def 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
我该如何解决这个问题?
最佳答案
将 pandas 导入为 pdfetch_housing_data()
导入 pandas 后。只需调用函数 fetch_housing_data() 即可。这应该可以解决问题。
这本书也有类似的错误,作者忘记添加一两行。
关于python-3.x - 当我尝试重新创建来自 Hands On Machine Learning with Sci-Kit Learn & Tensorflow 的住房数据集时,该数据集不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48472277/
我是一名优秀的程序员,十分优秀!