Premium problem31. Grouped Rolling Mean (ignore NaN)

Hard Locked

Compute a rolling mean (window 3) within each group, ignoring NaN values. df has columns 'group' and 'value'. Partial windows count, so the first two rows of each group average what is available so far rather than coming out as NaN. Return the resulting Series in the original row order.

Input

   group  value
0      a    1.0
1      a    2.0
2      b    3.0
3      b    NaN
4      a    2.0
5      b    3.0
6      b    NaN
7      b    1.0
8      a    7.0
9      b    3.0
10     a    NaN
11     b    8.0

Output

0     1.000000
1     1.500000
2     3.000000
3     3.000000
4     1.666667
5     3.000000
6     3.000000
7     2.000000
8     3.666667
9     2.000000
10    4.500000
11    4.000000
Name: value, dtype: float64

Premium problem

This one's part of Premium. Unlock the full Pandas track plus every other premium problem on the site.

Implement solve(...)