title: How can I create a dummy variable in Python with a condition below or above median?
body: <p>How can I create binary dummy variables in Python which takes the value of <code>0</code> when a person’s salary is below the median salary level and is set to <code>1</code> otherwise? I don't understand how to make it when salary above or below. </p>
  
  <p>I tried this</p>
  
  <pre><code>df['Salary'] = (df['Salary'] &gt; df['Salary'].median()) &amp; (df['Salary'] &lt; df['Salary'].median())
  </code></pre>
  
  <p>But there is no output.</p>
  
  <p>Before that I tried this:</p>
  
  <pre><code>df['Salary'].median()
  df_Salary = pd.get_dummies(df['Salary'].median())
  df_new = pd.concat([df, df_Salary], axis=1)
  df_new
  </code></pre>
  
  <p>And got this    </p>
  
  <pre><code>    Gender  Exp Salary  74000.0
  
  0   Female  15  78200   1
  1   Female  12  66400   NaN
  2   Female  3   6000    NaN
  ...
  </code></pre>