How to merge two dataframes side-by-side?

前端 未结 3 1673
耶瑟儿~
耶瑟儿~ 2020-11-30 09:47

is there a way to conveniently merge two data frames side by side?

both two data frames have 30 rows, they have different number of columns, say, df1 has 20 columns

3条回答
  •  失恋的感觉
    2020-11-30 10:17

    • There is way, you can do it via a Pipeline.

    ** Use a pipeline to transform your numerical Data for ex-

    Num_pipeline = Pipeline
    ([("select_numeric", DataFrameSelector([columns with numerical value])),
    ("imputer", SimpleImputer(strategy="median")),
    ])
    

    **And for categorical data

    cat_pipeline = Pipeline([
        ("select_cat", DataFrameSelector([columns with categorical data])),
        ("cat_encoder", OneHotEncoder(sparse=False)),
    ])
    

    ** Then use a Feature union to add these transformations together

    preprocess_pipeline = FeatureUnion(transformer_list=[
        ("num_pipeline", num_pipeline),
        ("cat_pipeline", cat_pipeline),
    ])
    
    • Read more here - https://scikit-learn.org/stable/modules/generated/sklearn.pipeline.FeatureUnion.html

提交回复
热议问题