Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- | A | B (Calculation) | B (Value) |
- |---|----------------------|-----------|
- | 1 | | |
- | 2 | | |
- | 3 | | |
- | 4 | =SUM(A1:A4)/4 | 2.5 |
- | 5 | =(1/4)*A5 + (3/4)*B4 | 3.125 |
- | 6 | =(1/4)*A6 + (3/4)*B5 | 3.84375 |
- | 7 | =(1/4)*A7 + (3/4)*B6 | 4.6328125 |
- # represent row numbers
- r = np.arange(len(df))
- # create same sized array filled with 3 (the fourth index)
- o = np.empty_like(r)
- o.fill(3)
- # take pair wise maximum. will look like [3 3 3 3 4 5 6]
- # this allows me to take the mean of the first 4 and the
- # existing values elsewehre
- np.stack([r, o]).max(0)
- # perform the groupby then ewma
- df.A.groupby(np.stack([r, o]).max(0)).mean().ewm(adjust=False, alpha=.25).mean()
- 3 2.500000
- 4 3.125000
- 5 3.843750
- 6 4.632812
- Name: A, dtype: float64
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement