Sean Fallon
Sean Fallon

Reputation: 9

Python 2.7 - Help on pandas_reader

Am replicating the code I have got from another website where in "pandas.io.data" has been commented out. Instead am using "pandas_datareader"

# Commodity Channel Index Python Code

# Load the necessary packages and modules
import pandas as pd
#import pandas.io.data as web
import pandas_datareader.data as web
import matplotlib.pyplot as plt

# Commodity Channel Index 

def CCI(data, ndays):
TP = (data['High'] + data['Low'] + data['Close']) / 3 
CCI = pd.Series((TP - pd.rolling_mean(TP, ndays)) / (0.015 * pd.rolling_std(TP, ndays)),
name = 'CCI') 
data = data.join(CCI) 
return data

My query is here for line 12 output that I get in the shell

Warning (from warnings module):

CCI = pd.Series((TP - pd.rolling_mean(TP, ndays)) / (0.015 * pd.rolling_std(TP, ndays)), FutureWarning: pd.rolling_mean is deprecated for Series and will be removed in a future version, replace with Series.rolling(window=20,center=False).mean()

Can anyone suggest how to correct the code?

Upvotes: 1

Views: 646

Answers (1)

jezrael
jezrael

Reputation: 863166

In version 0.18.0 was API changed - window functions are now methods:

So use:

CCI = pd.Series((TP - TP.rolling(ndays).mean()) / (0.015 * TP.rolling(ndays).std()),
name = 'CCI') 

instead:

CCI = pd.Series((TP - pd.rolling_mean(TP, ndays)) / (0.015 * pd.rolling_std(TP, ndays)),
name = 'CCI')

Upvotes: 1

Related Questions