Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
473 views
in Technique[技术] by (71.8m points)

python 3.x - how to find exponential weighted moving average using dataframe.ewma?

Previously I used the following to calculate the ewma

dataset['26ema'] = pd.ewma(dataset['price'], span=26)

But, in the latest version of pandas pd.ewma has been removed. How to calculate using the new method dataframe.ewma?

dataset['26ema'] = dataset['price'].ewma(span=26)

This is giving an error 'AttributeError: 'Series' object has no attribute 'ewma'

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use Series.ewm:

dataset['price'].ewm(span=26)

See GH11603 for the relevant PR and mapping of the old API to new ones.


Minimal Code Example

s = pd.Series(range(5))
s.ewm(span=3).mean()

0    0.000000
1    0.666667
2    1.428571
3    2.266667
4    3.161290
dtype: float64

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...