title: Creating a running total with max and min limits
body: <p>I'm calculating a running total for battery storage in an electricity grid simulator. </p>
  
  <p>While iterating through each line I need to add the previous value of <code>surpluses</code> to the previous value ([i-1]) of <code>battery</code> up to a maximum storage capacity of <code>s</code></p>
  
  <p><code>surpluses</code> is often negative so will often drop to a mimimum of 0</p>
  
  <p><strong>I need to start the iteration from the second value as the first value is</strong> <code>s</code></p>
  
  <p>I have created a series <code>battery</code> to iterate through and have tried the following</p>
  
  <p><code>surpluses</code> is also a series</p>
  
  <pre><code>for i, item in battery.iteritems()[1]:
      if (battery[i-1] + surpluses[i-1]) &lt; 0:
          battery[i] = 0
      elif (battery[i-1] + surpluses[i-1]) &gt; s:
          battery[i] = s
      else:
          battery[i] = battery[i - 1] + surpluses[i - 1]
  </code></pre>
  
  <p>So for example I want to use <code>s = 5</code> as  <code>battery[0]</code> then <code>battery[1] = battery[0] + surplus[0]</code> and so on. </p>
  
  <pre><code>surpluses
  -1
  -2
   1
  -4
  
  battery
  5
  4
  2
  3
  0
  </code></pre>
  
  <p>In this case, 5 is the max and 0 is the min which is why I have if statements to prevent the running total leaving this range. </p>
  
  <p><strong>Current errors</strong></p>
  
  <pre><code>if (batteryStorage[i-1] + surpluses[i-1]) &lt; 0:
  TypeError: unsupported operand type(s) for -: 'str' and 'int'
  </code></pre>
  
  <p>and</p>
  
  <pre><code>for i, item in batteryStorage.iteritems()[1]:
  TypeError: 'zip' object is not subscriptable```
  </code></pre>