I have a DataFrame and I would like to check if any of the values (v) of a column satisfies x<=v<=y
.
equal = any(df['columnX'] == value) # No problems here
in_between = any(x <= df['columnX'] <= y) # ValueError :/
The error I get is ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
But I am using any()
already!
So what's the problem here? Why does it work with ==
but not with x<=v<=y
?
Use
between
to do this, it also supports whether the range values are included or not viainclusive
arg:You then call
any
on the above:You can just have two conditions:
This line will select all rows in df where the condition is satisfied.
If you like to see other column values, you could try