【发布时间】:2021-01-17 16:57:23
【问题描述】:
这些是我存储在列表中的分类特征名称
my_list=['MSZoning','Street','LotShape','LandContour','Utilities','LotConfig','LandSlope',
'Neighborhood','Condition1','Condition2','BldgType','HouseStyle','RoofStyle','RoofMatl',
'Exterior1st','Exterior2nd','MasVnrType','ExterQual','ExterCond','Foundation','BsmtFinType2',
'Heating','HeatingQC','CentralAir','KitchenQual','Functional','GarageType','GarageFinish',
'GarageQual','GarageCond','PavedDrive','SaleType','SaleCondition']
我的编码代码如下:
for cols in my_list:
df[cols]=pd.get_dummies(df[cols],drop_first=True)
我收到以下错误:
KeyError: 'MSZoning'
During handling of the above exception, another exception occurred:
我对另一个数据集尝试了上述方法,但它工作得很好,但在这里它给了我上述错误。
【问题讨论】:
-
请添加您遇到的整个错误。您省略了部分错误消息。
标签: categorical-data one-hot-encoding keyerror