0

I have a 50 columns, categorical dataset. Among them only 5 columns are numerical. I would like to apply label encoder to make the categorical columns to numerical columns. Categorical columns are basically nominal columns for my dataset. I need to convert columns 0 to 4 to numerical and column 9 to 50 to numerical values.

I used the command

le = LabelEncoder()
df.iloc[:,0:4]=le.fit_transform(df.iloc[:,0:4])

df is the name of the dataframe.

error : ValueError: y should be a 1d array

How could I fix this problem? Thank you.

Encipher
  • 1,370
  • 1
  • 14
  • 31

1 Answers1

-1

use .apply() method of DataFrame to apply some rule to columns/rows. In your particular case it will be smth like this: df.apply(le.fit_transform) (notice that you need to add .iloc here)

Masha
  • 352
  • 1
  • 11