title: Create new column via boolean indexing while using two arrays of different size and index
body: <p>I have two data frames. Both of different sizes and of different indexes. However they have two columns of the same name: 'Start' and 'Stop'. I need to check every row in A to see if B's Start and Stop are between the Start and Stop in A. Here is a diagram:</p>
  
  <p>AStart --- BStart BStop --- AStop</p>
  
  <p>Upon determining if that is true, I need to increment a column in A called 'Inside' by 1, and go on to the next row in B and perform the same test.</p>
  
  <p>I am primarily getting hung up on the issue of combining the complicated boolean test with the task of: for every row in A, test every row in B</p>
  
  <p>I have tried using the .loc function and also using some sort of apply method, but I think I am just missing something for the .loc function.</p>
  
  <p>For the below code, I get a Value Error saying that I can only compare identically-labeled Series objects but I have tried dropping the indices and also using .value notation to try and get around that, but that hasn't worked.</p>
  
  <pre><code># I have tried:
   import pandas as pd
   import numpy as np
   A.loc[(A.Start &lt;= B.Start) &amp; (B.Stop &lt;= A.Stop), 'Inside'] += 1
  
  #----------
  #Ideally
  A = pd.DataFrame([[1,5], [4,7]], index=['Gene Z', 'Gene X'], columns = ['Start', 'Stop'])
  A
  
  
    #      Start  Stop
  #Gene Z      1     5
  #Gene X      4     7
  
  B = pd.DataFrame([[2,4], [4,9]], index=['Obj 1', 'Obj 2'], columns = ['Start', 'Stop']) 
  B
  
  #         Start  Stop
  #Obj 1      2     4
  #Obj 2      4     9
  
  # Output:
  A = pd.DataFrame([[1,5,1], [4,7,np.nan]], index=['Gene Z', 'Gene X'], columns = ['Start', 'Stop', 'Inside'])
  A
  
    #      Start  Stop Inside
   #Gene Z      1     5   1
   #Gene X      4     7   np.nan
  </code></pre>