result = result[(result['var'] > 0.25) or (result['var'] < -0.25)]
result = result[(result['var']>0.25) | (result['var']<-0.25)]
>>> import pandas as pd
>>> x = pd.Series([1])
>>> bool(x)
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
What you hit was a place where the operator implicitly converted the operands to bool (you used or but it also happens for and, if and while):
>>> x or x
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
>>> x and x
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
>>> if x:
... print('fun')
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
>>> while x:
... print('fun')
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Besides these 4 statements there are several python functions that hide some bool calls (like any, all, filter, ...) these are normally not problematic with pandas.Series but for completeness I wanted to mention these.
In your case the exception isn't really helpful, because it doesn't mention the right alternatives. For and and or you can use (if you want element-wise comparisons):
numpy.logical_or:
>>> import numpy as np
>>> np.logical_or(x, y)
or simply the | operator:
>>> x | y
numpy.logical_and :
>>> np.logical_and(x, y)
or simply the & operator:
>>> x & y
Or, alternatively, you could use Operator module. More detailed information is here Python docs
import operator
import numpy as np
import pandas as pd
np.random.seed(0)
df = pd.DataFrame(np.random.randn(5,3), columns=list('ABC'))
df.loc[operator.or_(df.C > 0.25, df.C < -0.25)]
A B C
0 1.764052 0.400157 0.978738
1 2.240893 1.867558 -0.977278
3 0.410599 0.144044 1.454274
4 0.761038 0.121675 0.4438
One minor thing, which wasted my time.
Put the conditions(if comparing using " = ", " != ") in parenthesis, failing to do so also raises this exception. This will work
df[(some condition) conditional operator (some conditions)]
This will not
df[some condition conditional-operator some condition]