title: Python Pandas Sum Values in Columns If date between 2 dates
body: <p>I have a dataframe <code>df</code> which can be created with this:</p>
  
  <pre><code>data={'id':[1,1,1,1,2,2,2,2],
        'date1':[datetime.date(2016,1,1),datetime.date(2016,1,2),datetime.date(2016,1,3),datetime.date(2016,1,4),
                 datetime.date(2016,1,2),datetime.date(2016,1,4),datetime.date(2016,1,3),datetime.date(2016,1,1)],
        'date2':[datetime.date(2016,1,5),datetime.date(2016,1,3),datetime.date(2016,1,5),datetime.date(2016,1,5),
                 datetime.date(2016,1,4),datetime.date(2016,1,5),datetime.date(2016,1,4),datetime.date(2016,1,1)],
        'score1':[5,7,3,2,9,3,8,3],
        'score2':[1,3,0,5,2,20,7,7]}
  df=pd.DataFrame.from_dict(data)
  
  And looks like this:
     id       date1       date2  score1  score2
  0   1  2016-01-01  2016-01-05       5       1
  1   1  2016-01-02  2016-01-03       7       3
  2   1  2016-01-03  2016-01-05       3       0
  3   1  2016-01-04  2016-01-05       2       5
  4   2  2016-01-02  2016-01-04       9       2
  5   2  2016-01-04  2016-01-05       3      20
  6   2  2016-01-03  2016-01-04       8       7
  7   2  2016-01-01  2016-01-01       3       7
  </code></pre>
  
  <p>What I need to do is create a column for each of <code>score1</code> and <code>score2</code>, which creates two columns which SUM the values of <code>score1</code> and <code>score2</code> respectively, based on whether the <code>usedate</code> is between <code>date1</code> and <code>date2</code>. <code>usedate</code> is created by getting all dates between and including the <code>date1</code> minimum and the <code>date2</code> maximum.  I used this to create the date range:</p>
  
  <pre><code>drange=pd.date_range(df.date1.min(),df.date2.max())    
  </code></pre>
  
  <p>The resulting dataframe <code>newdf</code> should look like:</p>
  
  <pre><code>     usedate  score1sum  score2sum
  0 2016-01-01          8          8
  1 2016-01-02         21          6
  2 2016-01-03         32         13
  3 2016-01-04         30         35
  4 2016-01-05         13         26
  </code></pre>
  
  <p>For clarification, on <code>usedate</code> 2016-01-01, <code>score1sum</code> is 8, which is calculated by looking at the rows in <code>df</code> where 2016-01-01 is between and including <code>date1</code> and <code>date2</code>, which sum row0(5) and row8(3).  On <code>usedate</code> 2016-01-04, <code>score2sum</code> is 35, which is calculated by looking at the rows in <code>df</code> where 2016-01-04 is between and including <code>date1</code> and <code>date2</code>, which sum row0(1), row3(0), row4(5), row5(2), row6(20), row7(7).</p>
  
  <p>Maybe some kind of <code>groupby</code>, or <code>melt</code> then <code>groupby</code>?   </p>