我正在尝试运行此代码,但它引发ValueError:当'YearBuilt'列不包含任何字符串时,无法将其转换为float:'YearBuilt'。
Score = pd.read_csv('Score_Data-No_Sale_Price.csv')
Score2 = Score[['PID','YearBuilt', 'YearRemodel', 'VeneerExterior','HeatingQC', 'FstFlrSqft',
'AbvGrndLiving', 'FullBathHouse', 'RmAbvGrnd',
'OverallQuality','LotArea', 'BldgTp']]
Score2.dtypes
_scaler = StandardScaler()
PDF_z2 = z_scaler.fit_transform(Score2.drop('PID', axis=1))
PDF_z2 = pd.DataFrame(PDF_z, columns=Score2.drop('PID', axis=1).columns)
imputer_by_median = SimpleImputer(strategy = 'median')
Scorecols = ['YearBuilt', 'YearRemodel', 'VeneerExterior','HeatingQC', 'FstFlrSqft',
'AbvGrndLiving', 'FullBathHouse', 'RmAbvGrnd',
'OverallQuality','LotArea', 'BldgTp']
dfImputeIntervalCols = PDF_z2[Scorecols].copy()
这是发生错误的地方
Score3 = pd.DataFrame(imputer_by_median.fit_transform(Scorecols),
columns = Scorecols, index = dfImputeIntervalCols.index)
display(dfImputedIntervals.shape, dfImputedIntervals.dtypes,
dfImputedIntervals.isnull().sum().sum())