title: Python Pandas Year To Date vs. Last Year To Date (YTD, LYTD)
body: <p>I am trying to solve for how to get the values of year to date versus last year to date from a dataframe.
  Dataframe:</p>
  <pre><code>ID      start_date   distance    
  1       2019-7-25    2
  2       2019-7-26    2
  3       2020-3-4     1
  4       2020-3-4     1
  5       2020-3-5     3
  6       2020-3-6     3
  </code></pre>
  <p>There is data back to 2017 and more data will keep getting added so I would like the YTD and LYTD to be dynamic based upon the current year.
  I know how to get the cumulative sum for each year and month but I am really struggling with how to calculate the YTD and LYTD.</p>
  <pre><code>    year_month_distance_df = distance_kpi_df.groupby([&quot;Start_Year&quot;,&quot;Start_Month&quot;]).agg({&quot;distance&quot;:&quot;sum&quot;}).reset_index()
  </code></pre>
  <p>The other code I tried:</p>
  <pre><code>cum_sum_distance_ytd = 
  distance_kpi_df[[&quot;start_date_local&quot;,&quot;distance&quot;]]
  cum_sum_distance_ytd = cum_sum_distance_ytd.set_index(&quot;start_date_local&quot;)
  cum_sum_distance_ytd = cum_sum_distance_ytd.groupby(pd.Grouper(freq = &quot;D&quot;)).sum()
  </code></pre>
  <p>When I try this logic and add Start_Day into the group by it obviously just sums all the data for that day.</p>
  <p>Expected output:
  Year to Date = 8
  Last Year to Date = 4</p>