title: Pandas lambda function syntax for working with strings
body: <p>I would like to use a lambda function on a whole dataframe column with a conditional to:</p>
  <ul>
  <li>remove the 3rd character</li>
  <li>replace the 4th &amp; 3rd last characters with a single dash '-'</li>
  <li>only when a value starts with 'AB'</li>
  </ul>
  <p>Such that 'AB123456789' becomes 'AB2345-89'</p>
  <pre><code>df = pd.DataFrame({'key':['123456789','AB123456789','CD123456789','987654321'],'adj_key':['123456789','AB123456789','CD123456789','987654321']})
      
  df['adj_key'] = df['adj_key'].apply(lambda x: (delete 3rd character &amp; replace 4th &amp; 3rd last character with a single dash) if (value begins with 'AB'))
  </code></pre>
  <p>result:</p>
  <pre><code>      key            adj_key   
  0     123456789      123456789    
  1     AB123456789    AB2345-89 
  2     CD123456789    CD123456789
  3     987654321      987654321
  </code></pre>
  <p>Cheers</p>