My pandas data frame looks like this:
id obal sprin prepayment obal_prepay
1 100 10 0.02
1 90 15 0.03
1 75 20 0.04
... ... ... ...
2 150 10 0.02
2 140 10 0.03
2 120 20 0.04
I need to apply following group wise operations:
- for every id-group, I need to add 1 row at the beginning which will contain one specific number of a different column.
for every id-group I have to do following "recurisve" calculation to get the "obal_prepay" values: obal_prepay[i]=obal[i-1]-prepayment*[obal_prepay[i-1]-sprin[i] For one simple example in an numpy array the code would look like this:
for i in range(1,len(id)): array[i,4]=array[i-1,0]-array[i-1,4]*array[i,3]- array[i,2]
The final data frame should look like this
id obal sprin prepayment obal_prepay
1 100 - - 100
1 100 10 0.02 100-100*0.02-10=88
1 90 15 0.03 100-88*0.03-15=82.36
1 75 20 0.04 90-82.36*0.04-20=...
... ... ... ...
2 150 - - 150
2 150 10 0.02 150-150*0.02-10=137
2 140 10 0.03 .. .
2 120 20 0.04 ..
Hope that was clear enough!
Thanks,
KS