title: Efficiently replace numbers in list of strings with a token
body: <p>I have lists of strings where some of the strings are integers. I'd like to find a way to quickly replace numbers over 100 with a token based off the length of the numbers.</p>
  
  <pre><code>['foo', 'bar', '3333'] -&gt; ['foo', 'bar', '99994']
  </code></pre>
  
  <p>I will be performing this operation millions of times over lists of length around 100. The pure python method I've come up with is as follows:</p>
  
  <pre><code>def quash_large_numbers(tokens, threshold=100):
      def is_int(s):
          try:
              int(s)
              return True
          except ValueError:
              return False
  
      BIG_NUMBER_TOKEN = '9999%d'
      tokens_no_high_nums = [BIG_NUMBER_TOKEN % len(t) if is_int(t) and int(t) &gt; threshold else t
                             for t in tokens]
      return tokens_no_high_nums
  </code></pre>
  
  <p>I was trying to see if I could do this more quickly via <code>pandas</code>, but it's much slower for small lists, I imagine from all the overhead from converting back and forth from series to list.</p>
  
  <pre><code>def pd_quash_large_numbers(tokens, threshold=100):
      BIG_NUMBER_TOKEN = 9999
      tokens_ser = pd.Series(tokens)
      int_tokens = pd.to_numeric(tokens_ser, errors='coerce')
      tokens_over_threshold = int_tokens &gt; threshold
      str_lengths = tokens_ser[tokens_over_threshold].str.len().astype(str)
  
      tokens_ser[tokens_over_threshold] = BIG_NUMBER_TOKEN + str_lengths
  
      return tokens_ser.tolist()
  </code></pre>
  
  <p>Is there a more efficient way I'm missing here? Possibly via cython?</p>