3 回答
TA贡献1803条经验 获得超6个赞
''
In [43]: df['Value'] = df.apply(lambda row: my_test(row['a'], row['c']), axis=1)In [44]: dfOut[44]: a b c Value 0 -1.674308 foo 0.343801 0.044698 1 -2.163236 bar -2.046438 -0.116798 2 -0.199115 foo -0.458050 -0.199115 3 0.918646 bar -0.007185 -0.001006 4 1.336830 foo 0.534292 0.268245 5 0.976844 bar -0.773630 -0.570417
In [53]: def my_test2(row):....: return row['a'] % row['c']....: In [54]: df['Value'] = df.apply(my_test2, axis=1)
TA贡献1827条经验 获得超8个赞
如果您只想计算(a列)%(b列),则不需要apply直接做就行了:
In [7]: df['a'] % df['c']
Out[7]:
0 -1.132022
1 -0.939493
2 0.201931
3 0.511374
4 -0.694647
5 -0.023486
Name: a
添加回答
举报