title: Extract a section of a string based on the value of another column in python
body: <p>I want to extra the first portion of column (B) based on the value of another column (A) minus 1 to get an output. Eg, if column A is 4 than I want the first 3 characters of column B. </p>
  
  <p>Any suggestions? Greatly appreciated!</p>
  
  <pre><code>+---+---------------+------+
  | A |       B       | Out  |
  +---+---------------+------+
  | 4 |  CTAAT        |  CTA |
  | 3 |  GKAEI        |  GK  |
  +---+---------------+------+
  </code></pre>
  
  <p>ie first 3 letters of column B in row 1, the fist 2 letters of column B in row 2.</p>
  
  <p>My current approach that isn't working:</p>
  
  <p><code>df['output']= df.B.str[0:(df[A]-1)]</code></p>