我有一个包含四列“ Lat,Long,age,age_s”的数据框。我想编写一个函数(包含for循环)以应用于数据框的age_s列。
这是我到目前为止编写的代码(但不起作用):
def bathy(row):
x = 0
for a in index:
x += (1. / ((1. + 2. * a)**2.))* (math.exp(-(k*((1.+2.*a)**2.)*(pi**2.)*row['age_s'])/(zp**2.)))
return (zr + (1. - (8. / pi**2. * x)) * (((rhom * ap * deltaT * zp) / (2. * (rhom -rhow)))))/ 1e3
tmp['bathy'] = tmp.apply(bathy, axis=1)
有人可以指出我哪里出问题了吗?
谢谢!
答案 0 :(得分:1)
你在这里。
tmp['bathy'] = tmp.apply(lambda row: bathy(row), axis=1)