0
for ma in ma_day:
    column_name = "MA for %s days" %(str(ma))
    AAPL[column_name] = pd.rolling_mean(AAPL['Adj Close'],ma)

I'm getting this error:

'module' object has no attribute 'rolling_mean'

I am working with python2

arghtype
  • 4,376
  • 11
  • 45
  • 60
  • 1
    Welcome to StackOverflow. Unfortunately, you have left out the context of your code snippet. What exactly does `pd` refer to--the `pandas` module? Are you sure that is what it really means? Please provide a complete section of code, one that runs and shows your problem. Read and follow [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – Rory Daulton Jan 21 '19 at 17:58

1 Answers1

0

pandas.rolling_mean is deprecated now, there's no such method, which gives an error (also, look here). There's no such method in actual pandas distributions. Instead you can use a combination of rolling and mean methods:

for ma in ma_day:
    column_name = "MA for %s days" %(str(ma))
    AAPL[column_name] = AAPL['Adj Close'].rolling(window=ma).mean()

Also you can install and use pandas versions ≤ 0.17, but it's deprecated and highly discouraged.

Mikhail Stepanov
  • 3,680
  • 3
  • 23
  • 24