0

The code is given below. I want to exclude two columns name 'Card Type' and 'Risk Value' from the label encoding code. How to exclude those? The below code encodes all object types into numerical. The columns are Alert number Job, Loan, City, Date, Card Type, Gender, Income level, EstimatedSalary, Risk Value

le = LabelEncoder()
objList = bank_dataset.select_dtypes(include="object").columns

for feat in objList:
    bank_dataset[feat] = le.fit_transform(bank_dataset[feat].astype(str))

2 Answers2

0

Use:

objList = bank_dataset.select_dtypes(include="object").columns

objList = objList.difference(['Card Type','Risk Value'], sort=False)

Or:

objList = [x for x in objList if x not in ['Card Type','Risk Value']]
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
0

Every dataset manipulation isn't done inplace by default, i would simply use the drop fuction like this:

objList = bank_dataset.drop(columns=['Card Type','Risk Value']).select_dtypes(include="object").columns