【问题标题】:'for' loop within a function函数内的“for”循环
【发布时间】:2019-09-12 05:11:54
【问题描述】:

我有一个包含四列“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)

谁能指出我哪里出错了?

谢谢!

【问题讨论】:

  • 请在问题中发布您的错误回溯。它可以帮助其他人更好地理解问题!谢谢

标签: python pandas function for-loop


【解决方案1】:

给你。

tmp['bathy'] = tmp.apply(lambda row: bathy(row), axis=1)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多