Integration with limits of a dataframe column

48 views Asked by At

Attempting to solve an integral using scipy quad to solve for the following:

Formula

I have a dataframe with a column of U/Udelta and when trying to apply

delta_115 = 3.41
def d_star_integrand_115(y, df_115, delta_115):
    return 1 - df_115['u/u_delta']


d_star_115, error_115 = quad(d_star_integrand_115, 
    0, delta_115, args=(df_115['u/u_delta'], delta_115) 

Could anyone let me know if you can even do an integral of a vectorised column in python or if that is not possible?

Have attempted multiple different options for the integrand, however all lead to the same error:

KeyError: 'u/u_delta'

Full traceback of the error

For reference the entire dataframe looks like this:

df_115

1

There are 1 answers

0
hpaulj On BEST ANSWER

The traceback says the keyerror is in d_star_integrand_115. The column indexing works ok in the quad call, but shouldn't be done again.

Corrected function

delta_115 = 3.41
def d_star_integrand_115(y, arg1, delta_115):
    return 1 - arg1  # arg1 is already a column


d_star_115, error_115 = quad(d_star_integrand_115, 
    0, delta_115, args=(df_115['u/u_delta'], delta_115)