Rahul R
Rahul R

Reputation: 141

Label Encoding of multiple columns without using pandas

Is there a simple way to label encode without using pandas for multiple columns?

Like using only numpy and sklearn's preprocessing.LabelEncoder()

Upvotes: 0

Views: 607

Answers (1)

MaxU - stand with Ukraine
MaxU - stand with Ukraine

Reputation: 210812

One solution would be to loop through the columns, converting them to numeric values, using LabelEncoder:

le = LabelEncoder()

cols_2_encode = [1,3,5] 

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

Upvotes: 1

Related Questions