使用
groupby
id
去拿那个
first
价值观。然后,使用
s
df.step
In [717]: s = df.groupby('id').transform('first')
In [718]: df.step + s.next_value - s.value
Out[718]:
0 187513.66079
1 387513.66079
2 2395.69480
3 2194.54149
4 67194.54149
5 87194.54149
6 152194.54149
7 202194.54149
8 202194.54149
9 202194.54149
10 202194.54149
11 6156.66299
12 26156.66299
13 36156.66299
14 41156.66299
15 31156.66299
16 31156.66299
17 36156.66299
18 31156.66299
19 76156.66299
20 146156.66299
21 143109.05475
22 11480.26440
23 61480.26440
24 61480.26440
25 61480.26440
26 61480.26440
27 61480.26440
28 6859.69952
29 26859.69952
dtype: float64
In [719]: s
Out[719]:
value next_value step
0 612486.33921 800000.0 0.0
1 612486.33921 800000.0 0.0
2 97604.30520 100000.0 0.0
3 97805.45851 100000.0 0.0
4 97805.45851 100000.0 0.0
5 97805.45851 100000.0 0.0
6 97805.45851 100000.0 0.0
7 97805.45851 100000.0 0.0
8 97805.45851 100000.0 0.0
9 97805.45851 100000.0 0.0
10 97805.45851 100000.0 0.0
11 33843.33701 40000.0 0.0
12 33843.33701 40000.0 0.0
13 33843.33701 40000.0 0.0
14 33843.33701 40000.0 0.0
15 33843.33701 40000.0 0.0
16 33843.33701 40000.0 0.0
17 33843.33701 40000.0 0.0
18 33843.33701 40000.0 0.0
19 33843.33701 40000.0 0.0
20 33843.33701 40000.0 0.0
21 241890.94525 385000.0 0.0
22 138519.73560 150000.0 0.0
23 138519.73560 150000.0 0.0
24 138519.73560 150000.0 0.0
25 138519.73560 150000.0 0.0
26 138519.73560 150000.0 0.0
27 138519.73560 150000.0 0.0
28 73140.30048 80000.0 0.0
29 73140.30048 80000.0 0.0