I have a data frame given below
[![enter image description here][1]][1]
example for year 2016 'div' should only have sum of 'avg_coef' across only 2016
and same for 2017 'div' should only have sum of 'avg_coef' across only 2017 and not any other value
I have almost achieved this by applying lambda but when applying it is only working for the last year in the loop and assigning other value in div as 0 as it move ahead in the loop, below is the code and output it is generating
[![enter image description here][1]][1]
[![enter image description here][1]][1]
some how it is only working for last year which is 2021, please also suggest you have a more optimized way of doing it, Thanks you all