title: Replace value in Pandas Dataframe based on condition
body: <p>I have a dataframe column with some numeric values. I want that these values get replaced by 1 and 0 based on a given condition. The condition is that if the value is above the mean of the column, then change the numeric value to 1, else set it to 0.</p>
  
  <p>Here is the code I have now:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  import pandas as pd
  
  dataset = pd.read_csv('data.csv')
  dataset = dataset.dropna(axis=0, how='any')
  
  X = dataset.drop(['myCol'], axis=1)
  y = dataset.iloc[:, 4:5].values
  
  mean_y = np.mean(dataset.myCol)
  </code></pre>
  
  <p>The target is the dataframe y. y is like so:</p>
  
  <pre><code>      0
  0    16
  1    13
  2    12.5
  3    12
  </code></pre>
  
  <p>and so on. mean_y is equal to 3.55. 
  Therefore, I need that all values greater than 3.55 to become ones, and the rest 0.</p>
  
  <p>I applied this loop, but without success:</p>
  
  <pre><code>for i in dataset.myCol:
      if dataset.myCol[i] &gt; mean_y:
          dataset.myCol[i] = 1
      else:
          dataset.myCol[i] = 0
  </code></pre>
  
  <p>The output is the following:</p>
  
  <pre><code>      0
  0    16
  1    13
  2    0
  3    12
  </code></pre>
  
  <p>What am I doing wrong? Can someone please explain me the mistake?</p>
  
  <p>Thank you!</p>