I have DataFrame as below:
df = pd.DataFrame((np.random.randn(5,4)*10).astype(int), columns=list('abcd'))
def cal(a, b):
if a + b > 5:
return a+b, a-b
how could I apply this function to df, the two variables cal take would be df['a'] and ['b'], the output a+b, a-b will be set to df['c'], df['d'].
loop the df works, but How could I use apply or applymap to achieve this (maybe cal need to be tweak)?