Dropping a column explicitly in DataFrameMapper

Viewed 1405

Consider the following artificial data:

data = pd.DataFrame({'pet':['cat', 'dog', 'dog', 'fish', 
                            'cat', 'dog', 'cat', 'fish'],
                     'children': [4., 6, 3, 3, 2, 3, 5, 4],
                     'salary':   [90., 24, 44, 27, 32, 59, 36, 27]})

In sklearn ColumnTransformer, I can drop any column I want by specifying 'drop' as the transformer as follows:

clmn_trnsfrmr = ColumnTransformer([
        ('clmn_drpr', 'drop', ['pet'])]),
        ('scale', StandardScaler(), ['salary']),
'passthrough'])

Is there a similar way in sklearn-pandas DataFrameMapper to drop exactly the column I want?

1 Answers

The documentation https://pypi.org/project/sklearn-pandas/1.5.0/ says "Only columns that are listed in the DataFrameMapper are kept. To keep a column but don’t apply any transformation to it, use None as transformer", so just don't list the column you want to get rid of.

Related