column_transformer = ColumnTransformer([("min_max_scaler", MinMaxScaler(), ["bill_length_mm", "bill_depth_mm", "flipper_length_mm"]), ("standard_scaler", StandardScaler(), ["body_mass_g"])])
Please note that the MinMaxScaler() works on “bill_length_mm”, “bill_depth_mm”, and “flipper_length_mm”. And the StandardScaler() works on “body_mass_g”.
After initializing the column transformer, we are calling the fit_transform() method that learns from the data and then, transforms the data.
The output of the above program will be:
<class 'pandas.core.frame.DataFrame'> RangeIndex: 344 entries, 0 to 343 Data columns (total 7 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 species 344 non-null object 1 island 344 non-null object 2 bill_length_mm 342 non-null float64 3 bill_depth_mm 342 non-null float64 4 flipper_length_mm 342 non-null float64 5 body_mass_g 342 non-null float64 6 sex 333 non-null object dtypes: float64(4), object(3) memory usage: 18.9+ KB None species island bill_length_mm ... flipper_length_mm body_mass_g sex 0 Adelie Torgersen 0.254545 ... 0.152542 -0.564142 Male 1 Adelie Torgersen 0.269091 ... 0.237288 -0.501703 Female 2 Adelie Torgersen 0.298182 ... 0.389831 -1.188532 Female 3 Adelie Torgersen NaN ... NaN NaN NaN 4 Adelie Torgersen 0.167273 ... 0.355932 -0.938776 Female [5 rows x 7 columns]






0 Comments