title: Vectorized comparison of values against a set of values
body: <p>I have a <code>pd.Dataframe</code> with a column that contains a value such as </p>
  
  <pre><code>df.iloc[:10]['occ']
  Out[18]: 
  0    4220
  1     205
  2    7630
  3    8965
  4     430
  5    3930
  6    4230
  7    5620
  8    4040
  9    4130
  </code></pre>
  
  <p>I then have another dataframe with <code>start</code> and <code>end</code> values for different groups. I want to assign groups to the first dataframe based on their <code>occ</code> value.</p>
  
  <pre><code>       start   end
  group             
  10        10   950
  11      1000  3540
  12      3600  3655
  13      3700  3955
  14      4000  4160
  </code></pre>
  
  <p>Since these groups are not intersecting, we have a simple bijection. I was planning to for each <code>occ</code> value, take the group-index of the last row that is smaller than the said <code>occ</code> value.</p>
  
  <pre><code>testAgainst = np.repeat(dfGroups['start'].values[np.newaxis, :], repeats=10, axis=0)
  
  array([[  10, 1000, 3600, 3700, 4000, 4200, 4300, 4700, 5000, 6000, 6200,
          7000, 7700, 9000],
         [  10, 1000, 3600, 3700, 4000, 4200, 4300, 4700, 5000, 6000, 6200,
          7000, 7700, 9000],
         [  10, 1000, 3600, 3700, 4000, 4200, 4300, 4700, 5000, 6000, 6200,
          7000, 7700, 9000],
         [  10, 1000, 3600, 3700, 4000, 4200, 4300, 4700, 5000, 6000, 6200,
          7000, 7700, 9000],
         [  10, 1000, 3600, 3700, 4000, 4200, 4300, 4700, 5000, 6000, 6200,
          7000, 7700, 9000],
         [  10, 1000, 3600, 3700, 4000, 4200, 4300, 4700, 5000, 6000, 6200,
          7000, 7700, 9000],
         [  10, 1000, 3600, 3700, 4000, 4200, 4300, 4700, 5000, 6000, 6200,
          7000, 7700, 9000],
         [  10, 1000, 3600, 3700, 4000, 4200, 4300, 4700, 5000, 6000, 6200,
          7000, 7700, 9000],
         [  10, 1000, 3600, 3700, 4000, 4200, 4300, 4700, 5000, 6000, 6200,
          7000, 7700, 9000],
         [  10, 1000, 3600, 3700, 4000, 4200, 4300, 4700, 5000, 6000, 6200,
          7000, 7700, 9000]])
  </code></pre>
  
  <p>And now, since the dimensions are <code>(10,)</code> and <code>(10, 14)</code>, there should automatic broadcasting happening. I am expecting to be able to do</p>
  
  <pre><code>df.iloc[:10]['occ'] &lt; testAgainst
  </code></pre>
  
  <p>and get as a result</p>
  
  <pre><code>0  False False False False False False True  True  True  True  True  True  True  True 
  1  False True  True  True  True  True  True  True  True  True  True  True  True  True 
  </code></pre>
  
  <p>for the first two rows, because <code>4220</code> is larger than <code>4200</code> (and all numbers thereafter), and <code>205</code> is larger than <code>10</code>.</p>
  
  <p>However, I get</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/foo/.conda/envs/myenv3/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2881, in run_code
      exec(code_obj, self.user_global_ns, self.user_ns)
    File "&lt;ipython-input-28-1bce7761846c&gt;", line 1, in &lt;module&gt;
      df.iloc[:10]['occ'] &lt; testAgainst
    File "/home/foo/.conda/envs/myenv3/lib/python3.5/site-packages/pandas/core/ops.py", line 832, in wrapper
      return self._constructor(na_op(self.values, np.asarray(other)),
    File "/home/foo/.conda/envs/myenv3/lib/python3.5/site-packages/pandas/core/ops.py", line 792, in na_op
      result = getattr(x, name)(y)
  ValueError: operands could not be broadcast together with shapes (10,) (10,14) 
  </code></pre>
  
  <ol>
  <li>Why is the broadcasting not working here?</li>
  <li>Given that this fails to work, what is the most efficient way to assign groups to my dataframe (real case: 10-15, groups, but 25 million rows in <code>df</code>).</li>
  </ol>