[英]python - replacing pd.rolling_apply in codes
I am referring to codes in the below link Identifying Extrema in Financial Data using Pandas我指的是以下链接中的代码使用 Pandas 识别财务数据中的极值
One of the functions has below code其中一个功能具有以下代码
def bear_market(symbol, window=90, correction = .2):
return pd.rolling_apply(symbol, window, lambda x: x[-1]/x.max() < (1-correction))
it seems rolling_apply is now replaced by rolling in python, but I am still struggling to amend this code似乎 rolling_apply 现在被 python 所取代,但我仍在努力修改此代码
pd.rolling_apply(symbol, window, lambda x: x[-1]/x.max() < (1-correction))
can someone help plz有人可以帮忙吗?
Series.rolling()
takes the window
param and Rolling.apply()
takes the lambda: Series.rolling()
采用window
参数, Rolling.apply()
采用 lambda:
def bear_market(symbol, window=90, correction=0.2):
return symbol.rolling(window).apply(lambda x: x[-1]/x.max() < (1-correction))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.