Advertisement
Guest User

Untitled

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