Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating Exponential Moving Average using pandas

I want to find out exponential moving average (12 days) for a dataframe. As given in the pandas documentation 0.19.2, I've used the function DataFrame.ewm to calcuate the exponential moving average. But it results in an error as follows AttributeError: 'DataFrame' object has no attribute 'ewm'. Below is the code I've used to calculate exponential moving average.

avg_gain=pd.gain.ewm(span=12,min_periods=12,adjust=False).mean()

On the other hand, in prior pandas documentation there is function ewma to calculate exponential moving average but this function results in undesired results. Can't figure out the issue?

like image 709
Furqan Hashim Avatar asked Apr 10 '26 22:04

Furqan Hashim


1 Answers

It seems that you are using an older version of pandas.

import pandas
pandas.__version__

To upgrade, use pip.

sudo pip3 install pandas --upgrade  # UNIX
pip install pandas --upgrade  # Windows

If you do not have pip installed, you can replace pip with python -m "pip", or pip3 with python3 -m "pip".

like image 189
Harrison Grodin Avatar answered Apr 12 '26 12:04

Harrison Grodin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!