I want to use FunctionTransformer to perform calculations between columns. For instance, I want to substract two columns and add the the new column to the dataset. So I have the function:
def diff(x, y):
return x - y
my initial dataset is:
X = pd.DataFrame({"product":["a","b","c","d"], "ndp":[100,200,150,120], "discount":[5,10,15,30]})
product ndp discount
0 a 100 5
1 b 200 10
2 c 150 15
3 d 120 30
and I need a new column price = ndp - discount, so I run:
from sklearn.preprocessing import FunctionTransformer
transf = FunctionTransformer(diff, kw_args={'x': 'ndp', 'y':"discount"})
func_transf.transform(X)
but I get an error:
TypeError: diff() got multiple values for argument 'x'
How can I pass the arguments to the function diff and how to specify the name of the new column?