I have a working bit of code equivalent to
def foo(x):
if (df.A == 0 or df.B > df.C):
return 0
else:
return (*some stuff*)
df['D'] = df.apply(lambda x: foo(x),axis=1)
Of course
_.apply(...,axis=1)_
is horribly slow and I want to do it efficiently. I tried the following:
crit = (df.A != 0 and df.B <= df.C) #this is just the negation of the previous boolean
df['D'] = 0
df.loc[crit,'D'] = (*some stuff*)
Here, I get an error:
_ValueError_, _the truth value of a Series is ambiguous_
If my crit only has one clause, it works fine, however. What am I missing here, and how do I fix it? I must confess I find it hard to grok how pandas does these things.