title: pandas apply function to series that checks if the first n characters matches a predefined string value, if so, the existing value needs to be updated
body: <p>I am trying to apply a function to a pandas series that checks the first 3 as well as the first 2 characters of the values in the series.</p>
  <p>If they match either, the first 3 or 2 characters (depending on which matched) needs to be replaced with '0', the rest of the characters remain the same.</p>
  <p>The original dtype was of type 'O', I have tried converting this to type 'string' but still can't get this to work.</p>
  <p>Sample data looks like so:</p>
  <pre><code>012xxxxxxx
  +27xxxxxxxx
  011xxxxxxx
  27xxxxxxxx
  etc...
  </code></pre>
  <p>The condition I am evaluating is if the first 3 characters == <em><strong>'+27'</strong></em> replace <em><strong>'+27'</strong></em> with <em><strong>'0'</strong></em> or if the first 2 characters == <em><strong>'27'</strong></em> replace <em><strong>'27'</strong></em> with <em><strong>'0'</strong></em></p>
  <p>I have the following <em><strong>apply method</strong></em> but the values aren't being updated.</p>
  <pre class="lang-py prettyprint-override"><code>def normalize_number(num):
         
      if num[:3] == '+27':
          # num.str.replace(num[:3], '0') ## First Method
          return '0' + num[4:] ## Second Method
      else:
          return num
          
      if num[:2] == '27':
          # num.str.replace(num[:2], '0') 
          return '0' + num[3:] 
      else:
          return num
  
  df['number'].apply(normalize_number)
  
  </code></pre>
  <p>What am I missing here?</p>