title: How to calculate difference of value between each date and category using groupby?
body: <p>I'm looking at the John Hopkins Dataset.</p>
  
  <p><a href="https://github.com/CSSEGISandData/COVID-19/blob/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv" rel="nofollow noreferrer">https://github.com/CSSEGISandData/COVID-19/blob/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv</a></p>
  
  <p>I have transformed it to the form (dummy data).</p>
  
  <pre><code>Country/Region  | Province/State |   Date     |   Type   | Cases | 
       US               Arizona      2020/03/14   Confirmed  100 
  Country/Region  | Province/State |   Date     |   Type   | Cases | 
       US               Arizona      2020/03/15   Confirmed  120 
  </code></pre>
  
  <p>What I want is to calculate the difference between date n and date n-1 for each country,region and case type.</p>
  
  <p>Something like</p>
  
  <pre><code>df['Difference'] = df.groupby(['Country/Region','Province/State','Type']).apply(...)
  </code></pre>
  
  <p>But I am not sure how to write the apply function.</p>
  
  <p>I want the output table to look like this.</p>
  
  <pre><code>Country/Region  | Province/State |   Date     |   Type   | Cases |  Difference
       US               Arizona      2020/03/14   Confirmed  100         ...
  Country/Region  | Province/State |   Date     |   Type   | Cases | 
       US               Arizona      2020/03/15   Confirmed  120         20
  </code></pre>
  
  <p>How is this achieved?</p>