Data frames are provided:
a = pd.DataFrame({'A':[1, 2]})
b = pd.DataFrame({'B':[2, 3]})
C = pd.DataFrame({'C':[4, 5]})
and list d = [A, C, B, B]
How to write an mathematical operations (((A + C) * B) - B) on frame values to create a new data frame?
The result is, for example, a frame in the form:
e = pd.DataFrame({'E':[8, 18]})
IIUC:
In [132]: formula = "E = (((A + C) * B) - B)"
In [133]: pd.concat([a,b,C], axis=1).eval(formula, inplace=False)
Out[133]:
A B C E
0 1 2 4 8
1 2 3 5 18
In [134]: pd.concat([a,b,C], axis=1).eval(formula, inplace=False)[['E']]
Out[134]:
E
0 8
1 18
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With