如何修复KeyError?

时间:2019-06-19 04:10:47

标签: python-3.x pandas

def create_dummies(df,col_name):
col_dummies=pd.get_dummies(df[col_name],prefix=col_name)
col_dummies.drop(col_dummies.columns[0],axis=1,inplace=True)
df=pd.concat(df[col_dummies],axis=1)
df.drop(col_name,axis=1,inplace=True)
return df
data_cat=data[['Brick','Neighborhood']]
for c_feature in ['Brick','Neighborhood']:
data_cat[data_cat['c_feature']]=data_cat[data_cat['c_feature']].astype('category')
    data_cat=create_dummies(data_cat,c_feature)
data_cat[data_cat['c_feature']]=data_cat[data_cat['c_feature']].astype('category')
    data_cat=create_dummies(data_cat,c_feature)



我正在使用实用程序功能为两个类别var的BrickNeighborhood创建假人。

我遇到c_feature的关键错误

0 个答案:

没有答案