首页 > 解决方案 > 如何将 pd.DataFrame.rolling.corr() 与 Kendall 的 Tau 或 Spearman 一起使用

问题描述

就像标题所暗示的那样,是否有一种内置方法可以在 df.rolling() 之上执行替代相关方法?我知道 df.rolling.apply(),但希望有一些内置的东西。

# Example
df = pd.DataFrame({'a':[1,2,3,4,5,6,7,100,9],
                   'b':[1,2,3,4,5,6,7,8,9]})

# These work, but are not what I want
df.rolling(3).corr()
df.corr(method='kendall')
>>> True

# This is what I want to do
df.rolling(3).corr(method='kendall')
>>> TypeError: count() got an unexpected keyword argument 'method'

标签: pythonpandasnumpy

解决方案


推荐阅读