复制我从其他网站获取的代码,其中“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行输出
警告(来自警告模块):
CCI = pd.Series((TP - pd.rolling_mean(TP,ndays))/(0.015 * pd.rolling_std(TP,ndays)), FutureWarning:pd.rolling_mean已弃用于系列,将在以后的版本中删除,替换为 Series.rolling(窗口= 20,中心=假).mean()
有人可以建议如何更正代码吗?
答案 0 :(得分:1)
在版本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')