BPt.Dataset.drop_cols#
- Dataset.drop_cols(scope='all', exclusions=None, inclusions=None, inplace=False)[source]#
This method is designed to allow dropping columns based on some flexible arguments. Essentially, exclusions, inclusions and scope are all scope style arguments for selecting subsets of columns, and the way they are composed to specify dropping a column is as follows:
For any given column, if within the columns selected by scope and EITHER in the passed exclusions columns or not in the passed inclusions columns, drop that column.
- Parameters
- scopeScope
default = 'all'
- exclusionsScope, optional
A BPt style Scope used to select a subset of columns in which if a column is in the selected subset of columns, it will be dropped (though if scope is set, then only those columns within scope will be checked to see if inside of the passed inclusions here.)
- inclusionsScope, optional
A BPt style Scope used to select a subset of columns in which if a column is not in the selected subset of columns, it will be dropped (though if scope is set, then only those columns within scope will be checked to see if outside of the passed inclusions here.)
- inplacebool, optional
If True, perform the current function inplace and return None.
default = False
Examples
Given the below dataset, we could try dropping some different columns. Each drop will be done on a copy of the Dataset.
In [1]: import BPt as bp In [2]: data = bp.Dataset(columns=['cat1', 'cat2', 'cat3', 'dog1', 'dog2']) In [3]: list(data) Out[3]: ['cat1', 'cat2', 'cat3', 'dog1', 'dog2'] In [4]: list(data.drop_cols(exclusions='cat')) Dropped 3 Columns Out[4]: ['dog1', 'dog2'] In [5]: list(data.drop_cols(exclusions='2', scope='cat')) Dropped 1 Columns Out[5]: ['cat1', 'cat3', 'dog1', 'dog2'] In [6]: list(data.drop_cols(inclusions=['1', '2'], scope='cat')) Dropped 1 Columns Out[6]: ['cat1', 'cat2', 'dog1', 'dog2'] In [7]: list(data.drop_cols(inclusions='dog')) Dropped 3 Columns Out[7]: ['dog1', 'dog2']