title: pandas adding a interpolator function conditionally as a new column
body: <p>I created a series of 5 <code>scipy</code> <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.CubicSpline.html" rel="nofollow noreferrer">cubic spline</a> (interpolator type) objects as follows:</p>
  <pre><code>from scipy.interpolate import CubicSpline
  def spline3(df, col1, col2):
      x, y = df[col1].values, df[col2].values
      cs = CubicSpline(x, y, bc_type='natural')
      return cs
  # indexed series of spline obj
  splines = avg_df.groupby('group').apply(spline3, 'tenor', 'mid')
  </code></pre>
  <p>resulting in:</p>
  <pre><code>    splines
      Out[129]: 
      group
      A     &lt;scipy.interpolate._cubic.CubicSpline object a...
      B    &lt;scipy.interpolate._cubic.CubicSpline object a...
      C    &lt;scipy.interpolate._cubic.CubicSpline object a...
      D    &lt;scipy.interpolate._cubic.CubicSpline object a...
      E    &lt;scipy.interpolate._cubic.CubicSpline object a...
      dtype: object
  </code></pre>
  <p>I.e., they will produce different interpolation for the same input <code>x</code> as could be seen below.  How to apply it to say this minimal data set as a new column:</p>
  <pre><code>toy = pd.DataFrame({
      'group': ['A', 'A', 'E'],
      'months': [11.04, 11.89, 7.51]
      })
  
  toy
  Out[132]: 
    group  months
  0     A   11.04
  1     A   11.89
  2     E    7.51
  </code></pre>
  <p>something like <code>toy['interpolated'] = splines[toy['MMD'](toy['months']</code> as below works:</p>
  <pre><code>splines['A'](7)
  Out[135]: array(0.90897722)
  
  splines['E'](7)
  Out[136]: array(1.74683114)
  </code></pre>
  <p>was thinking of <code>apply</code>\ <code>pipe</code> or <code>np.select</code> but it just escapes me this late on Friday.</p>