Python “TypeError: unhashable type: 'slice'” for encoding categorical data

后端 未结 7 911
长情又很酷
长情又很酷 2020-12-04 16:03

I am getting

TypeError: unhashable type: \'slice\'

when executing the below code for encoding categorical data in Python. Can a

7条回答
  •  时光说笑
    2020-12-04 16:55

    I was getting same error (TypeError: unhashable type: 'slice') with below code:

    included_cols = [2,4,10]
    dataset = dataset[:,included_cols]  #Columns 2,4 and 10 are included.
    

    Resolved with below code by putting iloc after dataset:

    included_cols = [2,4,10]
    dataset = dataset.iloc[:,included_cols]  #Columns 2,4 and 10 are included.
    

提交回复
热议问题