title: Pandas: Timeseries using predictions as ground truth
body: <p>I'm learning about time series and am trying to predict closing stock price for the next two weeks, given the data I already have (about a year).</p>
  
  <p>I've created 7 lag features using Pandas <code>shift</code>, so I have features <code>t-7, t-6, ..., t-1</code> and the current day's closing stock price for my whole DataFrame, <code>df</code>.  I've made a <code>test_df</code> which is just the last two weeks of data.  <code>test_df</code> has the true values for each of its row's lagged features.</p>
  
  <p>I want to mimic predicting future values by limiting myself to values from my training set (everything in <code>df</code> before the last two weeks) and my predictions.</p>
  
  <p>So I was going to do something like:</p>
  
  <pre><code># for each row in test_df
      # prediction = model.predict(row)
      # row["t"] = prediction
  </code></pre>
  
  <p>I think this is close, but it doesn't fix other lagged features like <code>t-1, t-2, ..., t-7</code>.  I need to do this:</p>
  
  <pre><code>row 2, t = prediction for row 1
  row 2, t-1 = t for row 1
  ...
  row 2, t-i = t-i+1 for row 1
  </code></pre>
  
  <p>And I would repeat this for all rows in my <code>test_df</code>.</p>
  
  <p>I could do this by writing my own function, but I'm wondering if there's a way to take advantage of Pandas to do this more easily.</p>
  
  <p>Edit for clarity:</p>
  
  <p>Suppose I'm looking at my first test row.  I don't have the <code>closing_price</code>, so I use my model to predict based on the lagged features.  Before prediction, my <code>df</code> looks like this:</p>
  
  <pre><code>  closing_price  t-1  t-2  t-3  t-4  t-5
  0          None    7    6    5    4    3
  </code></pre>
  
  <p>Suppose my prediction for <code>closing_price</code> is 15.  Then my updated DataFrame should look like this:</p>
  
  <pre><code>   closing_price   t-1  t-2  t-3  t-4  t-5
  0           15.0   7.0  6.0  5.0  4.0  3.0
  1            NaN  15.0  7.0  6.0  5.0  4.0
  </code></pre>
  
  <p>Thanks!</p>