Here one thing to note use np.log<i> or math.log
where is <i> base what ever you want
if you don't have any custom implementation log
function.
zr
should to change to 18
as per your statement formula
log(df['s_i']/df['s_18'])*log(i/18)
Here i am using similar layout dataframe
, please check out this code:
import numpy as np
import pandas as pd
h = [18, 56, 98, 123, 148]
df = pd.DataFrame(
data= np.arange(1, 51).reshape(10, 5),
columns= ['s_'+str(i) for i in h]
)
# here one point should be noted that `b += sum(a)` should be in outer `for-loop`
# otherwise as `a` grows at each iteration its `all items again added` so put
# `b += sum(a) in outer for-loop`
b = 0
for i in df.index:
a = []
for zi in h:
a.append(np.log(df.loc[i,'s_'+str(zi)]/df.loc[i,'s_18'])*np.log(zi/18))
b += sum(a)
print(b)
Method-2
equation = "np.log(df.loc[i,'s_'+str(j)]/df.loc[i,'s_18'])*np.log(j/18)"
b = 0
for i in df.index:
b += sum(list(map(lambda j: eval(equation), h)))
print(b)