这是我一直在努力的代码。
ThisWorkbook
错误描述如下
import numpy as np
import pandas as pd
from sklearn.datasets import load_boston
housing = load_boston()
housing = pd.DataFrame(housing.data, columns = housing.feature_names)
housing['target'] = pd.Series(housing.target)
AttributeError:“ DataFrame”对象没有属性“ target”
答案 0 :(得分:1)
之所以会这样,是因为您将pd.DataFrame
命名为与数据集完全相同,因此在housing.target
中,housing
引用了DataFrame
而不是数据集。将其更改为类似
housing = load_boston()
housing_df = pd.DataFrame(housing.data, columns = housing.feature_names)
housing_df['target'] = pd.Series(housing.target)
你很好。