Skip to content
Advertisement

How do I apply Sympy.Solve to solve a two-sided function on each row in a database?

I am attempting to apply the sympy.solve function to each row in a DataFrame using each column a different variable. I have managed to solve for the undefined variable I need to calculate — λ — using the following code:

JavaScript

However, I need to apply this function to every row in a DataFrame and output the result as its own column. The DataFrame is formatted as follows:

JavaScript

I have searched for how to do this, but am not sure how to proceed. I managed to find similar questions wherein the answers discussed lambdifying the equation, but I wasn’t sure how to lambdify a two-sided equation and then apply it to my DataFrame, and my math skills aren’t strong enough to isolate λ and place it on the left side of the equation so that I don’t have to lambdify a two-sided equation. Any help here would be appreciated.

Advertisement

Answer

You can use the apply method of a dataframe in order to apply a numerical function to each row. But first we need to create the numerical function: we are going to do that with lambdify:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement