title: complex merge pandas numpy with Aggregation
body: <p>I want to merge two dataframe and calculate the 3 columns witch an avergage of the past observation for a GIVEN ID . </p>
  
  <p>Here is an example :</p>
  
  <pre><code>contracts_data = np.array([
                          [1, '2015-01-01', 15000],
                          [2, '2015-01-01', 1500],
                          [1, '2015-08-01', 16000],
                          [2, '2015-08-01', 1800],
                          [1, '2015-10-01', 17000],
                          [1, '2016-01-01', 18000],
                          [1, '2016-03-01', 20000]])
  
  
      historique_data = np.array([[1, '2015-01-01'],
                          [2, '2015-01-01'],
                          [1, '2015-02-01'],
                          [2, '2015-02-01'],
                          [1, '2015-03-01'],
                          [2, '2015-03-01'],
                          [1, '2015-04-01'],
                          [2, '2015-04-01'],
                          [1, '2015-05-01'],
                          [2, '2015-05-01'],
                          [1, '2015-06-01'],
                          [2, '2015-06-01'],
                          [1, '2015-07-01'],
                          [2, '2015-07-01'],
                          [1, '2015-08-01'],
                          [2, '2015-08-01'],
                          [1, '2015-09-01'],
                          [2, '2015-09-01'],
                          [1, '2015-10-01'],
                          [2, '2015-10-01'],
                          [1, '2015-11-01'],
                          [2, '2015-11-01'],
                          [1, '2015-12-01'],
                          [2, '2015-12-01'],
                          [1, '2016-01-01'],
                          [2, '2016-01-01'],
                          [1, '2016-02-01'],
                          [2, '2016-02-01'],
                          [1, '2016-03-01'],
                          [2, '2016-03-01'],
                          [1, '2016-04-01'],
                          [2, '2016-04-01'],
                          [1, '2016-05-01'],
                          [2, '2016-05-01']])
  
      historique_data_expected = np.array([[1, '2015-01-01', 15000],
                          [2, '2015-01-01', 1500],
                          [1, '2015-02-01', 15000],
                          [2, '2015-02-01', 1500],
                          [1, '2015-03-01', 15000],
                          [2, '2015-03-01', 1500],
                          [1, '2015-04-01', 15000],
                          [2, '2015-04-01', 1500],
                          [1, '2015-05-01', 15000],
                          [2, '2015-05-01', 1500],
                          [1, '2015-06-01', 15000],
                          [2, '2015-06-01', 1500],
                          [1, '2015-07-01', 15000],
                          [2, '2015-07-01', 1500],
                          [1, '2015-08-01', 15500],
                          [2, '2015-08-01', 1650],
                          [1, '2015-09-01', 15500],
                          [2, '2015-09-01', 1650],
                          [1, '2015-10-01', 16000],
                          [2, '2015-10-01', 1650],
                          [1, '2015-11-01', 16000],
                          [2, '2015-11-01', 1650],
                          [1, '2015-12-01', 16000],
                          [2, '2015-12-01', 1650],
                          [1, '2016-01-01', 16500],
                          [2, '2016-01-01', 1650],
                          [1, '2016-02-01', 16500],
                          [2, '2016-02-01', 1650],
                          [1, '2016-03-01', 17200],
                          [2, '2016-03-01', 1650],
                          [1, '2016-04-01', 17200],
                          [2, '2016-04-01', 1650],
                          [1, '2016-05-01', 17200],
                          [2, '2016-05-01', 1650]])
  </code></pre>
  
  <ul>
  <li>The first column is the Join column . </li>
  <li>The second is the date </li>
  <li>The 3 is a salary . </li>
  </ul>
  
  <p>I want to join the 3 dataSet and for the Salary column i want to have the average of the past salary for the same ID . </p>
  
  <p>How this can be done using pandas and numpy or even another framework . </p>
  
  <p>Thanks in advance . </p>
  
  <p>===== UPDATE ==== </p>
  
  <p>I add here some more simple example of the two dataframe and the expected result : </p>
  
  <pre><code>ID  DATE          SALARY
  1   2015-01-01    1500    
  2   2015-01-01    1000    
  1   2015-03-01    1600    
  1   2015-04-01    1700    
  
  ID  DATE
  1   2015-01-01
  2   2015-01-01
  1   2015-02-01
  2   2015-02-01
  1   2015-03-01
  2   2015-03-01
  1   2015-04-01
  2   2015-04-01
  </code></pre>
  
  <p>The expected result : </p>
  
  <pre><code>ID  DATE
  1   2015-01-01  1500
  2   2015-01-01  1000
  1   2015-02-01  1500
  2   2015-02-01  1000
  1   2015-03-01  1550
  2   2015-03-01  1000
  1   2015-04-01  1600
  2   2015-04-01  1000
  </code></pre>
  
  <p>In other term I want to average past salary when merging the 2 datasets</p>