Furqan Hashim
Furqan Hashim

Reputation: 1318

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?

Upvotes: 3

Views: 2510

Answers (1)

Harrison Grodin
Harrison Grodin

Reputation: 2323

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".

Upvotes: 3

Related Questions