python - Pandas: how to match multiple pattern (OR) with np.where -
I would like to know whether it is possible with NP. For example, I try to create a new column in my dataframe called 'type' and fill it with "test" for each row. If the value is labeled in any other column named 'label', then
df ['kind'] = np.where (df ['label'] = = 'B85_C', 'test', 'control')
And it's working well with 1 pattern
What I see is Like this Something is:
df ['kind'] = np.where (df ['label'] == 'B85_C'OR' B85_N ',' test ',' control ')
How do any ideas or if there are options? Thank you
You can either use bitwise or:
(Df ['label'] == 'B85_C') | (DF ['label'] == 'b85_n')
Or you can use the method:
df ['label' ]. ['B85_C', 'B85_N'])
Comments
Post a Comment