How to filter array data using multiple condition? #6278
Answered
by
keewis
emaildipen
asked this question in
Q&A
-
I tried this but it didn't work, NT['DN'] = NTL['DN'].where(NT['Cloud_Mask']==50&58) It only filters the array values with NTL['Cloud_Mask']==50, in fact, I want to filter it using NT['Cloud_Mask'] that have values 50 and 58. |
Beta Was this translation helpful? Give feedback.
Answered by
keewis
Feb 15, 2022
Replies: 1 comment
-
the operator precedence causes NT['Cloud_Mask'] == (50 & 58) which means that it will first compute the bitwise-and of (NT['Cloud_Mask'] == 50) & (NT['Cloud_Mask'] == 58) However, you probably want to use NT['Cloud_Mask'].isin([50, 58]) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
dcherian
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the operator precedence causes
python
to interpret your expression as:which means that it will first compute the bitwise-and of
50
and58
(the result is50
), after which it will compare that to your array. To fix that, we need to introduce parens:However, you probably want to use
isin
instead: