title: Pandas - replaces values by other
body: <p>I have a pandas DataFame like this :</p>
  
  <pre><code>cols                col1      col2      col3      col4
  lines                                                  
  l1                  0.004975  0.004975  0.865672  0.99005
  l2                  0.004975  0.004975  0.865672  0.99005
  l3                  0.004975  0.004975  0.990050  0.99005
  l4                  0.004975  0.019900  0.865672  0.99005
  l5                  0.004975  0.004975  0.990050  0.99005
  l6                  0.004975  0.004975  0.865672  0.99005
  l7                  0.004975  0.004975  0.865672  0.99005
  l8                  0.004975  0.004975  0.865672  0.99005
  l9                  0.004975  0.019900  0.865672  0.99005
  </code></pre>
  
  <p>I want to replace every value by another : if the value is  &lt; 0.025, then it should be to 1, if > 0.0975 then it should be 3, and 2 in every other case.</p>
  
  <p>This code does the job :</p>
  
  <pre><code>x = len(list(df.index))
  y = len(list(df.columns))
  
  for i in range(x):
      l = df.iloc[i]
      for j in range(y) :
          if l[j] &lt; 0.025:
              l[j] = 1
          elif l[j] &gt; 0.975:
              l[j] = 3
          else:
              l[j] = 2
  </code></pre>
  
  <p>But this is quite ugly and I guess there is a much more elegant and pythonic way to do that ! I'm trying with <code>loc</code> and <code>mask</code> but no result for now. I also precise that the number and names of lines and columns can vary, so I'm working on a code which works in every case. Can someone show me a better code ?</p>