【发布时间】:2020-05-05 07:10:20
【问题描述】:
我正在尝试用数字替换分类变量以进行缩放;我的数据集被命名为银行但出现上述错误..有人可以帮忙吗 下面是我的代码
newstruct= {"job":{"blue-collar":1,"management":2,"technician":3,"admin":4,"services":5,"retired":6,"self-employed":7,
"entrepreneur":8,"unemployed":9,"housemaid":10,"student":11,"unknown":12},
"marital":{"married":2,"single":1,"divorced":3},
"education":{"secondary":2,"tertiary":3,"primary":1},
"default":{"yes":1,"no":0},
"housing":{"yes":1,"no":0},
"y":{"yes":1,"no":0},
"poutcome":{"unknown":4,"failure":2,"other":3,"success":1}}
bank=bank.replace(newstruct)
【问题讨论】:
-
我相信如果您提供更多背景信息会更容易回答这个问题。
-
这是为了将分类变量替换为数据中的序数值,所以习惯了用数字1,2等编码...最后使用了替换函数,但转换错误
标签: python string numpy dataframe