title: Pandas : How to replace values in a range with a string?
body: <p>I'm trying to replace values in a certain range with some other value.</p>
  
  <p>I have a dictionary containing a char as key and the upper range as a value like the following - </p>
  
  <pre><code>replace_dict = {
          'A': 10, 
          'B': 21, 
          'C': 34, 
          'D': 49, 
          'E': 66, 
          'F': 85, 
          'G': 107, 
          'H': 132, 
          'I': 160, 
          'J': 192, 
          'K': 229, 
          'L': 271, 
          'M': 319, 
          'N': 395, 
          'O': 495, 
          'P': 595, 
          'Q': 795, 
          'R': 1100
  }
  </code></pre>
  
  <p>I need to replace the values with the corresponding keys that fall in a range. </p>
  
  <p><strong>For example:</strong> </p>
  
  <pre><code>Values in the range of 1-10 will be replaced by 'A',
  Values in the range of 11-21 will be replaced by 'B'
  Values in the range of 22-34 will be replaced by 'C'
  Values in the range of 35-50 will be replaced by 'D'
  Values in the range of 51-66 will be replaced by 'E'
  </code></pre>
  
  <p>I've written the following code:</p>
  
  <pre><code>k=1
  for i, j in replace_dict.items():
      data.loc[data['my_col'].between(k,j)] = i
      k=j+1
  </code></pre>
  
  <p>This code shows <code>TypeError: '&gt;=' not supported between instances of 'str' and 'int'</code>.</p>
  
  <p>However, the line <code>data.loc[data['my_col'].between(1,10)] = 'A'</code> works fine.</p>
  
  <p>What is a good solution for this problem?</p>