Advertisement
naren_paste

Column Transformer

Dec 8th, 2023
709
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | Source Code | 0 0
  1. num_columns = [""] # Add the appropriate column names
  2. cat_columns = [""] # Add the appropriate column names
  3.  
  4. from sklearn.pipeline import Pipeline
  5. from sklearn.impute import SimpleImputer
  6. from sklearn.preprocessing import StandardScaler
  7. from sklearn.compose import ColumnTransformer
  8.  
  9. num_pipeline = Pipeline(
  10.                 steps=[
  11.                     ("impute", SimpleImputer(strategy="median")),
  12.                     ("scaler", StandardScaler()),
  13.                 ]
  14.             )
  15.  
  16. preprocessor = ColumnTransformer(
  17.                 transformers=[
  18.                     ("num_pipeline", num_pipeline, num_columns)
  19.                 ]
  20.             )
  21.  
  22. input_feature_train = df.drop('price', axis=1)
  23.  
  24. arr = pd.DataFrame(preprocessor.fit_transform(input_feature_train),columns=preprocessor.get_feature_names_out())
  25. print(arr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement