title: Pandas DataFrame: use column value to slice string in another column
body: <p>I have a pandas DataFrame as follow:</p>
  
  <pre><code>     col1  col2  col3
  0    1     3     ABCDEFG
  1    1     5     HIJKLMNO
  2    1     2     PQRSTUV
  </code></pre>
  
  <p>I want to add another column which should be a substring of <code>col3</code> from position as indicated in <code>col1</code> to position as indicated in <code>col2</code>. Something like <code>col3[(col1-1):(col2-1)]</code>, which should result in:</p>
  
  <pre><code>     col1  col2  col3       new_col
  0    1     3     ABCDEFG    ABC
  1    1     5     HIJKLMNO   HIJK
  2    1     2     PQRSTUV    PQ
  </code></pre>
  
  <p>I tried with the following:</p>
  
  <pre><code>my_df['new_col'] = my_df.col3.str.slice(my_df['col1']-1, my_df['col2']-1)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>my_df['new_col'] = data['col3'].str[(my_df['col1']-1):(my_df['col2']-1)]
  </code></pre>
  
  <p>Both of them results in a column of <code>NaN</code>, while if I insert two numerical values (i.e. <code>data['col3'].str[1:3]</code>) it works fine. I checked and the types are correct (int64, int64 and object). Also, outside such context (e.g. using a for loop) I can get the job done, but I'd prefer a one liner that exploit the DataFrame. What am I doing wrong?</p>