drop#
- skrub.selectors.drop(df, selector)[source]#
Select the columns of a dataframe that are NOT matched by the selector.
This is the complement of
select(): it returns a new dataframe containing all columns except those matched by the selector.- Parameters:
- Returns:
- dataframe
A new dataframe with the matched columns removed, preserving the order of remaining columns.
See also
Notes
dropis logically equivalent toselect(df, ~selector)orselect(df, s.all() - selector).droppreserves the original column order of the remaining columns.Examples
>>> from skrub import selectors as s >>> import pandas as pd >>> df = pd.DataFrame( ... { ... "height_mm": [210.0, 297.0], ... "width_mm": [188.5, 210.0], ... "kind": ["A5", "A4"], ... "ID": [5, 4], ... } ... ) >>> df height_mm width_mm kind ID 0 210.0 188.5 A5 5 1 297.0 210.0 A4 4
Drop columns matching a pattern:
>>> s.drop(df, s.glob("*_mm")) kind ID 0 A5 5 1 A4 4
Drop specific columns by name (can pass names directly):
>>> s.drop(df, ['height_mm', 'width_mm']) kind ID 0 A5 5 1 A4 4
Preserve only certain types (via drop):
>>> s.drop(df, s.all() - s.string()) kind 0 A5 1 A4