title: Python pandas linear regression groupby
body: <p>I am trying to use a linear regression on a group by pandas python dataframe: </p>
  
  <p>This is the dataframe df:</p>
  
  <pre><code>  group      date      value
      A     01-02-2016     16 
      A     01-03-2016     15 
      A     01-04-2016     14 
      A     01-05-2016     17 
      A     01-06-2016     19 
      A     01-07-2016     20 
      B     01-02-2016     16 
      B     01-03-2016     13 
      B     01-04-2016     13 
      C     01-02-2016     16 
      C     01-03-2016     16 
  
  #import standard packages
  import pandas as pd
  import numpy as np
  
  #import ML packages
  from sklearn.linear_model import LinearRegression
  
  #First, let's group the data by group
  df_group = df.groupby('group')
  
  #Then, we need to change the date to integer
  df['date'] = pd.to_datetime(df['date'])  
  df['date_delta'] = (df['date'] - df['date'].min())  / np.timedelta64(1,'D')
  </code></pre>
  
  <p>Now I want to predict the value for each group for 01-10-2016. </p>
  
  <p>I want to get to a new dataframe like this: </p>
  
  <pre><code>group      01-10-2016
    A      predicted value
    B      predicted value
    C      predicted value
  </code></pre>
  
  <p>This <a href="https://stackoverflow.com/questions/24088439/how-to-apply-ols-from-statsmodels-to-groupby">How to apply OLS from statsmodels to groupby</a> doesn't work</p>
  
  <pre><code>for group in df_group.groups.keys():
        df= df_group.get_group(group)
        X = df['date_delta'] 
        y = df['value']
        model = LinearRegression(y, X)
        results = model.fit(X, y)
        print results.summary()
  </code></pre>
  
  <p>I get the following error</p>
  
  <pre><code>ValueError: Found arrays with inconsistent numbers of samples: [ 1 52]
  
  DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and   willraise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.DeprecationWarning)
  </code></pre>
  
  <p>UPDATE: </p>
  
  <p>I changed it to </p>
  
  <pre><code>for group in df_group.groups.keys():
        df= df_group.get_group(group)
        X = df[['date_delta']]
        y = df.value
        model = LinearRegression(y, X)
        results = model.fit(X, y)
        print results.summary()
  </code></pre>
  
  <p>and now I get this error: </p>
  
  <pre><code>ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
  </code></pre>