title: Add new column to Pandas Dataframe from functions' output
body: <p>I wrote function to estimate parameters of simple linear regression. The function produces several outputs. Function inputs are two <strong>lists</strong>. Also, I have initial DataFrame df from where I derived two lists.</p>
  
  <p>I want to add some outputs from function to the initial DataFrame as a new columns or either have new lists outside to function.</p>
  
  <p>for example:</p>
  
  <pre><code>def predict(X,Y):
       beta1 = sum([(X[i] - mean_X)*(Y[i] - mean_Y) for i in range(len(X))]) / sum([(X[i] - mean_X)**2 for i in range(len(X))])
       beta0 = mean_Y - beta1 * mean_X
  
       y_hat = [beta0 + beta1*X[i] for i in range(len(X))]
  
       return df.assign(prediction = y_hat)
  </code></pre>
  
  <p>Here, mean_X and mean_Y is sample average for list X and list Y, respectively.</p>
  
  <p>Also I tried <strong>numpy.insert()</strong> to add y_hat into not initial DataFrame but into X which I converted into numpy array.</p>
  
  <p>I have no success to achieve desired result so can someone help me?</p>