Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions examples/0010_apply_to_cols.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
Hands-On with Column Selection and Transformers
===============================================

In previous examples, we saw how skrub provides powerful abstractions like
:class:`~skrub.TableVectorizer` and :func:`~skrub.tabular_pipeline` to create pipelines.

In this new example, we show how to create more flexible pipelines by selecting
and transforming dataframe columns using arbitrary logic.

.. |ApplyToCols| replace:: :class:`~skrub.ApplyToCols`
.. |StringEncoder| replace:: :class:`~skrub.StringEncoder`
Expand All @@ -18,6 +13,9 @@
.. |Pipeline| replace:: :class:`~sklearn.pipeline.Pipeline`
.. |ColumnTransformer| replace:: :class:`~sklearn.compose.ColumnTransformer`

In this example, we show how to create flexible pipelines by selecting
and transforming dataframe columns using arbitrary logic with |ApplyToCols|.

"""

# %%
Expand All @@ -40,7 +38,7 @@
# choosing: ``division`` and ``employee_position_title``.
#
# We can achieve this using |ApplyToCols|, whose job is to apply a
# transformer to multiple columns independently, and let unmatched columns through
# transformer to multiple columns in parallel, and let unmatched columns through
# without changes.
# This can be seen as a handy drop-in replacement of the
# |ColumnTransformer|.
Expand Down Expand Up @@ -100,17 +98,6 @@
apply_pca,
).fit_transform(X)

# %%
# .. admonition:: Under the hood of |ApplyToCols|
# :collapsible: closed
#
# |ApplyToCols| is implemented using the ``ApplyToEachCol`` and ``ApplyToSubFrame``
# classes.
# The former applies a transformer to each column independently, while the latter
# applies a transformer to a sub-dataframe.
# Normally, users don't need to worry about these two classes, but they can be useful
# when more control is needed.

# %%
# Note that selectors also come in handy in a pipeline to select or drop columns, using
# |SelectCols| and |DropCols|.
Expand Down
Loading