Home > Software engineering >  Standardization or Normalization for selected columns
Standardization or Normalization for selected columns

Time:06-07

**from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train[:,5:7] = sc.fit_transform(X_train[:,5:7])**

Here I want to select 5th, 6th and 9th columns.

Is there a way to select the 9th column here??

CodePudding user response:

In order to select 5th,6th and 9th columns, you can use .iloc. Note the column index starts from 0. So, the indices of 5,6, and 9th columns are 4,5 and 8.

    from sklearn.preprocessing import StandardScaler
    sc = StandardScaler()
    X_train.iloc[:, [4,5,8]] = sc.fit_transform(X_train.iloc[:, [4,5,8]])

CodePudding user response:

Yes this will work X_train[:,[5,6,8]].

Thanks @StupidWolf

  • Related