I have a function that requires three arguments:
def R0(confirm, suspect,t):
p = 0.695
si = 7.5
yt = suspect * p + confirm
lamda = math.log(yt)/t
R0 = 1 + lamda * si + p * (1 - p) * pow(lamda * si,2)
return R0
And a dataframe with three columns:
data = {'confirm': ['41', '41', '43', '44'],
'suspect': ['0', '0', '0', '10'],
't': ['0', '1', '2', '3']
}
df = pd.DataFrame (data, columns = ['confirm','suspect', 't'])
I would like to use each row (with three columns, and hence three values) as the argument values for the function. Finally, I would like to loop over rows of the dataframe and return a list.
For instance, the results should look like:
result = [R0_Value1, R0_Value2, R0_Value3, ....] where
R0_Value1 = R0(41, 0, 0)
R0_Value2 = R0(41, 0, 1)
R0_Value3 = R0(43, 0, 2)
...
I figure out it probably has something to do with pandas.DataFrame.apply and *. But I am new to Python and could not figure out how to do it. Could someone please help?