dtoolkit.transformer.FilterInTF#
- class dtoolkit.transformer.FilterInTF(*args, **kwargs)[source]#
A transformer could filter
DataFramecontents.See also
dtoolkit.accessor.dataframe.filter_inThis transformer’s prototype method.
Examples
>>> from dtoolkit.transformer import FilterInTF >>> import pandas as pd >>> df = pd.DataFrame( ... { ... 'legs': [2, 4, 2], ... 'wings': [2, 0, 0], ... }, ... index=['falcon', 'dog', 'cat'], ... ) >>> df legs wings falcon 2 2 dog 4 0 cat 2 0
When
conditionis a list check whether every value in the DataFrame is present in the list (which animals have 0 or 2 legs or wings).Filter rows.
>>> tf = FilterInTF([0, 2]) >>> tf.transform(df) legs wings falcon 2 2 cat 2 0
When
conditionis adict, we can pass values to check for each column separately:>>> tf = FilterInTF({'legs': [2], 'wings': [2]}) >>> tf.transform(df) legs wings falcon 2 2
When
valuesis a Series or DataFrame the index and column must match. Note thatfalcondoes not match based on the number of legs in df2.>>> other = pd.DataFrame({'legs': [8, 2], 'wings': [0, 2]}, ... index=['spider', 'falcon']) >>> other legs wings spider 8 0 falcon 2 2 >>> tf = FilterInTF(other) >>> tf.transform(df) legs wings falcon 2 2
- Attributes
- inverse_transform_method
Methods
fit(*_)Fit transformer.
fit_transform(X[, y])Fit to data, then transform it.
Undo transform to
X.set_output(*[, transform])Set output container.
transform(X)Transform
X.transform_method(df, condition, /[, how, ...])Filter
DataFramecontents.update_invargs(*args, **kwargs)Inverse transform method argument entry.