title: Sum weekly totals of values from one data frame based on dates in another data frame in python
body: <p>I want to sum the values in one column of a dataframe for certain dates that are defined by another dataframe. </p>
  
  <p>My first dataframe of dates looks like this:</p>
  
  <pre><code>import numpy as np
  import pandas as pd
  
  start_date = ["2-22-16 00:00:00", "2-29-16 00:00:00", "3-7-16 00:00:00", "3-14-16 00:00:00", "3-21-16 00:00:00", "3-28-16 00:00:00", "4-4-16 00:00:00", "4-11-16 00:00:00", "4-18-16 00:00:00", "4-25-16 00:00:00", "5-2-16 00:00:00", "5-9-16 00:00:00", "5-16-16 00:00:00", "5-23-16 00:00:00", "5-30-16 00:00:00", "6-6-16 00:00:00", "6-13-16 00:00:00", "6-20-16 00:00:00", "6-27-16 00:00:00", "7-4-16 00:00:00", "7-11-16 00:00:00", "7-18-16 00:00:00", "7-25-16 00:00:00", "8-08-16 00:00:00", "8-22-16 00:00:00", "8-29-16 00:00:00", "9-5-16 00:00:00", "9-12-16 00:00:00", "9-19-16 00:00:00", "9-26-16 00:00:00", "10-3-16 00:00:00", "10-10-16 00:00:00", "10-17-16 00:00:00", "10-24-16 00:00:00", "10-31-16 00:00:00", "11-7-16 00:00:00", "11-14-16 00:00:00", "11-21-16 00:00:00", "1-23-17 00:00:00", "1-30-17 00:00:00", "2-06-17 00:00:00", "3-13-17 00:00:00", "3-27-17 00:00:00", "6-19-17 00:00:00", "6-26-17 00:00:00"]
  start_date = [pd.to_datetime(d) for d in start_date]
  end_date = pd.DatetimeIndex(start_date) + pd.DateOffset(7)
  ndf = pd.DataFrame({'start':pd.to_datetime(start_date),'end':end_date}); ndf.head()
  </code></pre>
  
  <p>What I want is values from another data frame that fall within the weeks defined in <code>ndf</code>.  My other dataframe looks something like this:</p>
  
  <pre><code>dates = ["4-17-16 04:00:00", "4-16-16 19:30:00", "4-16-16 19:00:00", "2-24-16 09:00:00", "3-21-16 02:00:00", "3-18-16 10:00:00", "3-24-16 05:00:00", "3-11-16 00:00:00"]
  df = pd.DataFrame(
      {'timestamp': dates,
       'value': np.random.randint(1,25,size=(8,))})
  </code></pre>
  
  <p>Now I want to create a new data frame that sums all the <code>values</code> from <code>df</code> that fall between the dates in <code>ndf</code>. So I created this function:</p>
  
  <pre><code>def get_dates(x):
      # Select the df values between start and ending datetime. 
      n = df[(df['timestamp']&gt;ndf['start'])&amp;(df['timestamp']&lt;ndf['end'])]
      # Return sum of values
      return n.values[0],n['value'].sum()
  </code></pre>
  
  <p>I also played around with this: <code>n = df[(df['timestamp']&gt;ndf['start'])&amp;(df['timestamp']&lt;ndf['end'])]</code>. But I get the error: <code>ValueError: Can only compare identically-labeled Series objects</code>. </p>
  
  <p>I'm looking for someone to help me clean up my function so that it works or provide insight on the error message above. Thanks!</p>