title: How to add column with accumulations of certain values from another column?
body: <p>Here is my table:</p>
  <pre><code>     date           id  action     value
      2021-09-02      aa  income      500
      2021-09-02      aa  spending    500
      2021-09-02      aa  spending    45
      2021-09-03      aa  income      30
      2021-09-03      aa  income      30
      2021-09-03      aa  spending    25
      2021-09-04      b1  income      100
      2021-09-05      b1  income      500
      2021-09-05      b1  spending    500
      2021-09-05      b1  spending    45
      2021-09-06      b1  income      30
      2021-09-06      b1  income      30
      2021-09-07      b1  spending    25
  </code></pre>
  <p>As you see there is two types of actions &quot;income&quot; and &quot;spending&quot;. What I want is to add column with accumulation of &quot;value&quot; at each moment for each of my id. And after each action &quot;income&quot; it must increase by value of that &quot;income&quot; and when there is &quot;spending&quot; it must decrease by value of that decrease.  So result must look like this:</p>
  <pre><code>     date           id  action     value    saved 
      2021-09-02      aa  income      500      0
      2021-09-02      aa  spending    400      500
      2021-09-02      aa  spending    40       100
      2021-09-03      aa  income      30       60     
      2021-09-03      aa  income      30       90
      2021-09-03      aa  spending    25       120
      2021-09-04      b1  income      100      0
      2021-09-05      b1  income      500      100
      2021-09-05      b1  spending    500      600
      2021-09-05      b1  spending    45       100
      2021-09-06      b1  income      30       55
      2021-09-06      b1  income      30       85
      2021-09-07      b1  spending    25       115
  </code></pre>
  <p>How to do that?</p>