gpt4 book ai didi

Python 2.7 - pandas_reader 帮助

转载 作者:太空宇宙 更新时间:2023-11-03 16:27:29 24 4
gpt4 key购买 nike

正在复制我从另一个网站获得的代码,其中“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')

关于Python 2.7 - pandas_reader 帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37879296/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com