LabelEncoder: TypeError: '>' not supported between instances of 'float' and 'str'

前端 未结 3 1371
一生所求
一生所求 2021-01-30 00:25

I\'m facing this error for multiple variables even treating missing values. For example:

le = preprocessing.LabelEncoder()
categorical = list(df.select_dtypes(in         


        
3条回答
  •  旧巷少年郎
    2021-01-30 00:32

    As string data types have variable length, it is by default stored as object type. I faced this problem after treating missing values too. Converting all those columns to type 'category' before label encoding worked in my case.

    df[cat]=df[cat].astype('category')
    

    And then check df.dtypes and perform label encoding.

提交回复
热议问题