Below is my sample dataframe df, with many variables where C is one among them, the length of the column in a variable.
ID C
1 0
2 1.47349678
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 0
11 0
12 0
13 0
14 0
16 1.987
17 0
18 0
19 0
20 0
21 0
22 0
23 0
24 0
25 0
26 0
27 0
I need to create another variable C_C where it consists of product of Cand a decremental factor by 0.1.
The multiplication has to be done only for the count of 10 values of C_C from the point where there is a value of Cother than 0. Also the result has to be stored from the next data point. i.e If C !=0 is found at Id ==2 then the product must be stored from ID==3
If there are less than 10 continuous zeroes after a non zero number would the count just reset to the new value of C, and if there is no further data found the multiplication will stop.
Expected Result
ID C C_C
1 0 0
2 1.47349678 0
3 0 1.47349678
4 0 1.326147102
5 0 1.178797424
6 0 1.031447746
7 0 0.884098068
8 0 0.73674839
9 0 0.589398712
10 0 0.442049034
11 0 0.294699356
12 0 0.147349678
13 0 0
14 0 0
16 1.987 0
17 0 1.987
18 0 1.7883
19 0 1.5896
20 0 1.3909
21 0 1.1922
22 0 0.9935
23 0 0.7948
24 0 0.5961
25 0 0.3974
26 0 0.1987
27 0 0
Observation from the Required Result
1. Value in C which is not 0is enocunter at ID = 2, so the product is being stored from ID == 3 i.e C_C3.
2. C_C3 == C2 * 1, C_C4 == C2*0.9, C_C5 == C2 * 0.8......C_C12 == C*0.1,
C_C13 == C2 *0.
3. Similarly C_C17 == C16 * 1, C_C18 == C16*0.9, C_C19 == C16 *0.8, .... C_C26 == C16 *0.1, C_C27 == C16*0
Thanks!
Cfor multiplication. - Tareva