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

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -