title: Pandas add column with value based on condition based on other columns
body: <p>I have the following pandas dataframe:</p>
  <p><a href="https://i.stack.imgur.com/zMiCD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zMiCD.png" alt="df" /></a></p>
  <pre class="lang-py prettyprint-override"><code>import pandas as pd
  import numpy as np
  
  d = {'age' : [21, 45, 45, 5],
       'salary' : [20, 40, 10, 100]}
  
  df = pd.DataFrame(d)
  </code></pre>
  <p>and would like to add an extra column called &quot;is_rich&quot; which captures if a person is rich depending on his/her salary. I found multiple ways to accomplish this:</p>
  <pre class="lang-py prettyprint-override"><code># method 1
  df['is_rich_method1'] = np.where(df['salary']&gt;=50, 'yes', 'no')
  
  # method 2
  df['is_rich_method2'] = ['yes' if x &gt;= 50 else 'no' for x in df['salary']]
  
  # method 3
  df['is_rich_method3'] = 'no'
  df.loc[df['salary'] &gt; 50,'is_rich_method3'] = 'yes'
  </code></pre>
  <p>resulting in:</p>
  <p><a href="https://i.stack.imgur.com/kodEo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kodEo.png" alt="df2" /></a></p>
  <p>However I don't understand what the preferred way is. Are all methods equally good depending on your application?</p>