2017-06-05 33 views
0

有沒有一種簡單的方法來標記編碼而不使用多個列的熊貓。 像只使用numpy的和sklearn的preprocessing.LabelEncoder()不使用熊貓而對多列進行標籤編碼

+2

據我所知,你會通過你的欄目需要循環並使用'LabelEncoder'轉換每個'string'列 – MaxU

回答

1

一個解決辦法是通過列循環,將它們轉換成數值,例如用LabelEncoder

le = LabelEncoder() 

cols_2_encode = [1,3,5] 

for col in cols_2_encode: 
    X[:, col] = le.fit_tramsform(X[:, col])