title: Python Pandas - Rolling regressions for multiple columns in a dataframe
body: <p>I have a large dataframe containing daily timeseries of prices for 10,000 columns (stocks) over a period of 20 years (5000 rows x 10000 columns). Missing observations are indicated by NaNs.</p>
  
  <pre><code>            0      1      2      3      4      5       6      7      8      \
  31.12.2009  30.75  66.99    NaN    NaN    NaN    NaN  393.87  57.04    NaN   
  01.01.2010  30.75  66.99    NaN    NaN    NaN    NaN  393.87  57.04    NaN   
  04.01.2010  31.85  66.99    NaN    NaN    NaN    NaN  404.93  57.04    NaN   
  05.01.2010  33.26  66.99    NaN    NaN    NaN    NaN  400.00  58.75    NaN   
  06.01.2010  33.26  66.99    NaN    NaN    NaN    NaN  400.00  58.75    NaN   
  </code></pre>
  
  <p>Now I want to run a rolling regression for a 250 day window for each column over the whole sample period and save the coefficient in another dataframe</p>
  
  <p>Iterating over the colums and rows using two for-loops isn't very efficient, so I tried this but getting the following error message</p>
  
  <pre><code>def regress(start, end):
      y = df_returns.iloc[start:end].values
  
      if np.isnan(y).any() == False:
          X = np.arange(len(y))
          X = sm.add_constant(X, has_constant="add")
          model = sm.OLS(y,X).fit()
  
          return model.params[1]
  
      else:
          return np.nan
  
  
  regression_window = 250
  
  for t in (regression_window, len(df_returns.index)):
  
      df_coef[t] = df_returns.apply(regress(t-regression_window, t), axis=1)
  </code></pre>
  
  <pre><code>TypeError: ("'float' object is not callable", 'occurred at index 31.12.2009')
  </code></pre>