how do I fix this "AttributeError: 'list' object has no attribute 'astype'"

how do I fix this "AttributeError: 'list' object has no attribute 'astype'"

我的代码有问题,不知何故存在 astype 问题,我想我需要对数据进行一些清理。但是我不确定,这种情况可以做什么?对于数据清理,我尝试了一些功能,例如 value_count 但没有帮助。您认为这里有什么问题?

  file_name='https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DA0101EN-SkillsNetwork/labs/FinalModule_Coursera/data/kc_house_data_NaN.csv'
df=pd.read_csv(file_name)

     features =["floors", "waterfront","lat" ,"bedrooms" ,"sqft_basement" ,"view" ,"bathrooms","sqft_living15","sqft_above","grade","sqft_living"]  
        Input=[('scale',StandardScaler()),('polynomial', PolynomialFeatures(include_bias=False)),('model',LinearRegression())]
        y=df['price']
        pipe=Pipeline(Input)
        print(pipe)
        features=features.astype(float)
        pipe.fit(features,y)
        ypipe=pipe.predict(features)
        ypipe[0:10]

您需要使用 features 列表到数据框中的 select 列。 features 是一个字符串列表,没有名为 astype 的属性。所以,代码会变成这样。

df[features]=df[features].astype(float)
pipe.fit(df[features],y)
ypipe=pipe.predict(df[features])