I work with pandas, but I do not have much experience. I have the following DataFrame:
A 0 NaN 1 0.00 2 0.00 3 3.33 4 10.21 5 6.67 6 7.00 7 8.27 8 6.07 9 2.17 10 3.38 11 2.48 12 2.08 13 6.95 14 0.00 15 1.75 16 6.66 17 9.69 18 6.73 19 6.20 20 3.01 21 0.32 22 0.52
and I need to calculate the total amount of the previous 11 lines. If before there were less than 11, the remaining ones are considered 0.
B 0 NaN 1 0.00 2 0.00 3 0.00 4 3.33 5 13.54 6 20.21 7 27.20 8 35.47 9 41.54 10 43.72 11 47.09 12 49.57 13 51.65 14 58.60 15 58.60 16 57.02 17 53.48 18 56.49 19 56.22 20 54.16 21 51.10 22 49.24
I tried:
df['B'] = df.A.cumsum().shift(-11).fillna(0)
However, this does not achieve what I want, but it leads to a rotation of the result of the total amount. How can I achieve this?
source share