'Fill null and next value with avarge value

i work with customers consumptions and sometime didn't have this consumption for month or more so the first consumption after that need to break it down into those months example

df = pd.DataFrame({'customerId':[1,1,1,1,1,1,1,2,2,2,2,2,2,2],
                   'month':['2021-10-01','2021-11-01','2021-12-01','2022-01-01','2022-02-01','2022-03-01','2022-04-01','2021-10-01','2021-11-01','2021-12-01','2022-01-01','2022-02-01','2022-03-01','2022-04-01'],
                   'consumption':[100,130,0,0,400,140,105,500,0,0,0,0,0,3300]})

bfill() return same value not mean (value/count of null +1) desired value

'c':[100,130,133,133,133,140,105,500,550,550,550,550,550,550]


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source