I am studying this snippet and I don't understand how to column addition was constructed.
def column_addition(X):
return X[:, [0]] + X[:, [1]]
def addition_pipeline():
return make_pipeline(
SimpleImputer(strategy="median"),
FunctionTransformer(column_addition))
preprocessing = ColumnTransformer(
transformers=[("accompany", addition_pipeline, ["SibSp", "Parch"])], remainder='passthrough')
preprocess = preprocessing.fit_transform(df)
How is the df
, and ["SibSp", "Parch"]
running in background to create an addition in the code below
# How is the df and ["SibSp", "Parch"] implemented here?
# How can I replicate this as a non-function?
X[:, [0]] + X[:, [1]]
When I try to replace the X
with the dataframe it throws an error.