title: How can I subtract values of one column rows from another column row which is preceding on the basis of Year period?
body: <p>I have a table which has various columns but I will only mention those which are on focus of interest.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Year</th>
  <th>Current Amount</th>
  <th>Previous Amount</th>
  <th>Type</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>2021</td>
  <td>22000</td>
  <td>36000</td>
  <td>C5 70</td>
  </tr>
  <tr>
  <td>2022</td>
  <td>26000</td>
  <td>48000</td>
  <td>C4 68</td>
  </tr>
  <tr>
  <td>2023</td>
  <td>76440</td>
  <td>34000</td>
  <td>C5 70</td>
  </tr>
  <tr>
  <td>2024</td>
  <td>21399</td>
  <td>12000</td>
  <td>C4 68</td>
  </tr>
  <tr>
  <td>2024</td>
  <td>22000</td>
  <td>11000</td>
  <td>C4 34</td>
  </tr>
  <tr>
  <td>2024</td>
  <td>26500</td>
  <td>13000</td>
  <td>C4 23</td>
  </tr>
  <tr>
  <td>2025</td>
  <td>16000</td>
  <td>34000</td>
  <td>C4 68</td>
  </tr>
  <tr>
  <td>2025</td>
  <td>76000</td>
  <td>22000</td>
  <td>C4 34</td>
  </tr>
  <tr>
  <td>2025</td>
  <td>34000</td>
  <td>64000</td>
  <td>C4 23</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Now obviously there are way to many year values. What I want is to deduct the current amount value when year is suppose 2022 from previous amount when year is 2021, In simple words, Subtract Current amount from Previous amount where every year value for Previous amount is preceding than the default value. For instance I want the results to look like this.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Year</th>
  <th>Current Amount</th>
  <th>Previous Amount</th>
  <th>Type</th>
  <th>Change</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>2021</td>
  <td>22000</td>
  <td>36000</td>
  <td>C5 70</td>
  <td>Nan</td>
  </tr>
  <tr>
  <td>2022</td>
  <td>26000</td>
  <td>48000</td>
  <td>C4 68</td>
  <td>-10,000</td>
  </tr>
  <tr>
  <td>2023</td>
  <td>76440</td>
  <td>34000</td>
  <td>C5 70</td>
  <td>28,440</td>
  </tr>
  <tr>
  <td>2024</td>
  <td>21399</td>
  <td>12000</td>
  <td>C4 68</td>
  <td>35899</td>
  </tr>
  <tr>
  <td>2024</td>
  <td>22000</td>
  <td>11000</td>
  <td>C4 34</td>
  <td>35899</td>
  </tr>
  <tr>
  <td>2024</td>
  <td>26500</td>
  <td>13000</td>
  <td>C4 23</td>
  <td>35899</td>
  </tr>
  <tr>
  <td>2025</td>
  <td>16000</td>
  <td>34000</td>
  <td>C4 68</td>
  <td>90000</td>
  </tr>
  <tr>
  <td>2025</td>
  <td>76000</td>
  <td>22000</td>
  <td>C4 34</td>
  <td>90000</td>
  </tr>
  <tr>
  <td>2025</td>
  <td>34000</td>
  <td>64000</td>
  <td>C4 23</td>
  <td>90000</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I have tried using following code but no luck so far :</p>
  <pre><code>Df['Current Amount'] - Df['Previous Amount'].where(Df['Year']==Df['Year']-1)
  </code></pre>
  <p>Also:</p>
  <pre><code>Df['Current Amount'] - Df['Previous Amount'].where(Df['Year']==Df['Year'].shift(-1))
  </code></pre>
  <p>Please help me. Thanks in Advance.</p>