Ordinal encoder with column transformer changing column index after executing

163 Views Asked by At

I am using ordinal encoder to convert categorical variables in to numeric for one of my dataframe. as i am using ordinal encoder in column transformer and fitting my pipeline. My columns index are getting shuffled.

imputer transformer

imputer_transformer = ColumnTransformer(transformers=[
            ('imputer_1',SimpleImputer(strategy='most_frequent'),[0,16]),
            ('imputer_2',SimpleImputer(strategy='median'),[4]),
            ('imputer_3',SimpleImputer(strategy='constant',fill_value='Other'),[13])
        ],remainder='passthrough')

encoding transformer

transformer_1 = ColumnTransformer(transformers=[
        ('ord_encoder',OrdinalEncoder(),[0])]
       ,remainder='passthrough')

standard scaling transformer

transformer_2 = ColumnTransformer([
        ('scaling',StandardScaler(),slice(0,44))])

pipe=make_pipeline(imputer_transformer,transformer_1)

new_df=pd.DataFrame(data=pipe.fit_transform(X_train_os))

--on running above code, i got

Dataframe output

My original dataframe was-

dataframe before encoding and pipeline fit

0

There are 0 best solutions below