title: Calculating sums of observation in time intervals in a df
body: <p>I've posted this as another <a href="https://stackoverflow.com/questions/66426324/calculating-a-sum-of-observations-for-time-intervals-in-a-df">question</a>, but realised I've got my sample data wrong.</p>
  <p>I've got two separate datasets. <code>df1</code> looks like this:</p>
  <pre><code>loc_ID  year  observations
  nin212  2002  90
  nin212  2003  98
  nin212  2004  102
  cha670  2001  18
  cha670  2002  19
  cha670  2003  21
  </code></pre>
  <p><code>df2</code> looks like this:</p>
  <pre><code>loc_ID  start_year  end_year  
  nin212  2002        2003 
  nin212  2003        2004
  cha670  2001        2002
  cha670  2002        2003
  </code></pre>
  <p>I want to calculate the number of <code>observations</code> in the time intervals (<code>start_year</code> to <code>end_year</code>) per <code>loc_ID</code>. In the example above, I would like to achieve this final dataset:</p>
  <pre><code>loc_ID  start_year  end_year observations 
  nin212  2002        2003     188
  nin212  2003        2004     200 
  cha670  2001        2002     37
  cha670  2002        2003     40
  </code></pre>
  <p>How could I do this?</p>