title: Variable bins for each row in pandas dataframe
body: <p>Given a coordinate dataframe such as <code>df1 = pd.DataFrame({'x': np.tile(np.arange(20),5), 'y': np.repeat(np.arange(5),20)})</code></p>
  
  <p>I would like to bin each x value however, the number of bins varies for each row. More specifically, the number of bins is dependent on the y value.</p>
  
  <p>e.g. point x=6 and y=2 
  if the number of bins = y+1 = 3
  then the bins for this row are (0, 6.33], (6.33, 12.67], (12.67, 19] and the resulting bin is (0, 6.33]</p>
  
  <p>Part of the resulting dataframe would look like:</p>
  
  <pre><code>x    y    xbinned
  18   2    (12.67, 19]
  19   2    (12.67, 19]
  0    3    (0, 4.75]
  1    3    (0, 4.75]
  </code></pre>
  
  <p>The following generates the desired bins:</p>
  
  <pre><code>xbins = []
  
  for y in df1.y:
      xbins.append(np.linspace(df1['x'].min(), df1['x'].max(), y+1))
  </code></pre>
  
  <p>But cannot be used in the cut:</p>
  
  <pre><code>df['xbinned'] = pd.cut(df.x, bins=xbins)
  </code></pre>
  
  <p>since it expects a 1d array not 2d.</p>
  
  <p>Where do I go from here? I think I would be able to do this using loops, but was hoping to use the pandas functions for a more vectorised solution.</p>