Selector#
- class skrub.selectors.Selector[source]#
Generic selector type, that returns set columns when applied.
This class is not meant to be instantiated manually,
Selectorobjects are created by calling one of the selector builders such asskrub.selectors.all()orskrub.selectors.make_selector().Methods
expand(df)Lists the column names that the selector would retain if applied to the dataframe
df.expand_index(df)Lists the indices of dataframe df's columns that the selector would retain if applied to df.
- expand(df)[source]#
Lists the column names that the selector would retain if applied to the dataframe
df.- Parameters:
- dfdataframe
- Returns:
listThe list of
df’s columns that the item would select.
Notes
In effect, running
df[sel.expand(df)]should give the exact same result assel.transform(df).Examples
>>> import pandas as pd >>> from skrub import selectors as s >>> some_selector = ~s.glob("*_mm") >>> df = pd.DataFrame( ... { ... "height_mm": [210.0, 297.0], ... "width_mm": [188.5, 210.0], ... "kind": ["A5", "A4"], ... "ID": [5, 4], ... } ... ) >>> some_selector.expand(df) ['kind', 'ID']
- expand_index(df)[source]#
Lists the indices of dataframe df’s columns that the selector would retain if applied to df.
- Parameters:
- dfdataframe
- Returns:
listThe list of indices among
df’s columns that the item would select.
Notes
In effect, (as with
expand), ifcolsis the list of columns indf, runningdf[cols[i] for i in sel.expand(df)]should give the exact same result assel.transform(df).Examples
>>> import pandas as pd >>> from skrub import selectors as s >>> some_selector = ~s.glob("*_mm") >>> df = pd.DataFrame( ... { ... "height_mm": [210.0, 297.0], ... "width_mm": [188.5, 210.0], ... "kind": ["A5", "A4"], ... "ID": [5, 4], ... } ... ) >>> some_selector.expand_index(df) [2, 3]