为什么我的Pandas‘Apply’函数不能引用多个列?
df = DataFrame ({'a' : np.random.randn(6), 'b' : ['foo', 'bar'] * 3, 'c' : np.random.randn(6)})
def my_test(a, b): return a % b
df['Value'] = df.apply(lambda row: my_test(row[a], row[c]), axis=1)
NameError: ("global name 'a' is not defined", u'occurred at index 0')
def my_test(a): cum_diff = 0 for ix in df.index(): cum_diff = cum_diff + (a - df['a'][ix]) return cum_diff
慕码人8056858
斯蒂芬大帝
相关分类