I have a dataframe with many rows, and having columns a
, b
, and c
. Something like:
| a | b | c
--------------------
0 | 10.1| .01 | 3.0
1 | 9.7| .02 | 2.0
2 | 11.2| .03 | 1.0
...| ... | ... | ...
and a function foo(x_, a, b, c)
that takes a
, b
, and c
as parameters. I want find the root of the function for each choice of values for the parameters.
This is how I currently implement it:
from scipy.optimize import root
df.apply(lambda x: root(foo, 0.0, args=(x["a"], x["b"], x["c"])), axis=1)
The problem is that it is very slow and I would like to somehow parallelize it to speed things up. (My understanding is that apply
with axis=1
simply loops through all of the rows.) What are some ways to achieve faster performance in python?