正在复制我从另一个网站获得的代码,其中“pandas.io.data”已被注释掉。相反,我使用“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
我的查询是在 shell 中获得的第 12 行输出
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 withSeries.rolling(window=20,center=False).mean()
有人可以建议如何更正代码吗?
在版本 0.18.0
中,API 已更改 - window functions are now methods :
所以使用:
CCI = pd.Series((TP - TP.rolling(ndays).mean()) / (0.015 * TP.rolling(ndays).std()),
name = 'CCI')
相反:
CCI = pd.Series((TP - pd.rolling_mean(TP, ndays)) / (0.015 * pd.rolling_std(TP, ndays)),
name = 'CCI')
我是一名优秀的程序员,十分优秀!