【问题标题】:Geting an error saying Cannot compare types 'ndarray(dtype=int64)' and 'str'收到错误提示无法比较类型 'ndarray(dtype=int64)' 和 'str'
【发布时间】: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


【解决方案1】:

错误很明显,你需要使用int("0")之类的函数将'str'转换为整数。

为了让我们提供帮助,您需要向我们提供更多信息,例如进行比较的位置。代码和错误到底是什么。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-12
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 2019-06-27
    • 1970-01-01
    • 2017-02-05
    • 1970-01-01
    相关资源
    最近更新 更多