Sergio Espejo Sergio Espejo - 9 months ago 37
Python Question

How do you use the values of a dataframe as a variable in a function to make a different column

I have a dataframe which i want to use as the values in it as the "x" in the function


here is my code


I keep getting the error
TypeError: can't multiply sequence by non-int of type 'float'


If you want to apply the function 0.00459652*np.exp(4.5*x)+0.000984312 to each value in the Temperature column, just put that column at the x location:

test = 0.00459652*np.exp(4.5*df['Temperature'])+0.000984312

The reason why you get that error is that x is a python list, which cannot be multiplied by a floating number (4.5 in this case). But df['Temperature'] can (it's a pandas.Series)

Also, 0.00459652*np.exp(4.5*x)+0.000984312 is not a python function. You need lambda x : 0.00459652*np.exp(4.5*x)+0.000984312