dtoolkit.transformer.EvalTF#
- class dtoolkit.transformer.EvalTF(*args, **kwargs)[source]#
A transformer could evaluate a string describing operations on
DataFrame
columns.See also
pandas.DataFrame.eval
This transformer’s prototype method.
Notes
eval()
’sinplace
parameter is not work for this transformer. Actually this break pipeline stream. If a transformer’sinplace
isTrue
, the next tf input would getNone
.Examples
>>> import pandas as pd >>> from dtoolkit.transformer import EvalTF >>> df = pd.DataFrame({'A': range(1, 6), 'B': range(10, 0, -2)}) >>> df A B 0 1 10 1 2 8 2 3 6 3 4 4 4 5 2 >>> tf = EvalTF('A + B') >>> tf.transform(df) 0 11 1 10 2 9 3 8 4 7 dtype: int64
Assignment is allowed though by default the original DataFrame is not modified.
>>> tf = EvalTF('C = A + B') >>> tf.transform(df) A B C 0 1 10 11 1 2 8 10 2 3 6 9 3 4 4 8 4 5 2 7 >>> df A B 0 1 10 1 2 8 2 3 6 3 4 4 4 5 2
Multiple columns can be assigned to using multi-line expressions:
>>> tf = EvalTF( ... ''' ... C = A + B ... D = A - B ... ''' ... ) >>> tf.transform(df) A B C D 0 1 10 11 -9 1 2 8 10 -6 2 3 6 9 -3 3 4 4 8 0 4 5 2 7 3
- 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
(self, expr, *[, inplace])Evaluate a string describing operations on DataFrame columns.
update_invargs
(*args, **kwargs)Inverse transform method argument entry.