Pass Pandas DataFrame to Scipy.optimize.curve_fit
<p>I'd like to know the best way to use Scipy to fit Pandas DataFrame columns. If I have a data table (Pandas DataFrame) with columns (<code>A</code>, <code>B</code>, <code>C</code>, <code>D</code> and <code>Z_real</code>) where Z depends on A, B, C and D, I want to fit a function of each DataFrame row (Series) which makes a prediction for Z (<code>Z_pred</code>). </p>

<p>The signature of each function to fit is </p>

<pre><code>func(series, param_1, param_2...)
</code></pre>

<p>where series is the Pandas Series corresponding to each row of the DataFrame. I use the Pandas Series so that different functions can use different combinations of columns. </p>

<p>I've tried passing the DataFrame to <code>scipy.optimize.curve_fit</code> using</p>

<pre><code>curve_fit(func, table, table.loc[:, 'Z_real'])
</code></pre>

<p>but for some reason each func instance is passed the whole datatable as its first argument rather than the Series for each row. I've also tried converting the DataFrame to a list of Series objects, but this results in my function being passed a Numpy array (I think because Scipy performs a conversion from a list of Series to a Numpy array which doesn't preserve the Pandas Series object).</p>