Premium problem30. Patch Negatives with Group Mean

Hard Locked

Build df with vals = np.random.RandomState(31).randint(-30, 30, size=15) and grps = np.random.RandomState(31).choice(['A','B'], 15). Return a Series replacing each negative value in 'vals' with the mean of the non-negative values in its group.

Output

0     13.6
1     28.0
2     13.6
3      4.0
4     13.6
5     28.0
6     13.6
7     13.6
8      8.0
9     28.0
10    28.0
11    12.0
12    16.0
13    13.6
14    13.6
Name: vals, 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(...)