title: How to iterate pandas Dataframe month-wise to satisfy demand over time
body: <p>Suppose I have a dataframe <code>df</code></p>
  <pre><code>   pd  demand  mon1  mon2  mon3
    abc1     137    46    37    31
    abc2     138    33    37    50
    abc3     120    38    47    46
    abc4     149    39    30    30
    abc5     129    33    42    42
    abc6     112    30    45    43
    abc7     129    43    33    45
  </code></pre>
  <p>I want to satisfy the demand of each <code>pd</code> month-wise. I am generating some random numbers which indicate satisfied demand. For example, for pd <code>abc1</code>, demand is 137, say I have produced 42 units for mon1, but mon1 demand is 46. Hence revised dataframe would be</p>
  <pre><code>   pd    demand                       mon2                               mon3
    abc1  137 - 42=  95   37 + 4 (Unsatisfied demand for previous month)    31
  </code></pre>
  <p>Then it will run for mon2 and so on. In this way, I would like to capture, how much demand would be satisfied for each <code>pd</code> (excess or unsatisfied).</p>
  <p>My try:</p>
  <pre><code>import pandas as pd
  import random
  mon = ['mon1', 'mon2', 'mon3']
  
  for i in df['pd'].values.tolist():
      t = df.loc[df['pd'] == i, :]
      for m in t.columns[2:]:
          y = t[m].iloc[0]
          n = random.randint(20, 70)
          t['demand'] = t['demand'].iloc[0] - n
  </code></pre>
  <p>Not finding the logic exactly.</p>