Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
475 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...