pandas 如何计算与熊猫的滚动相关性?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51957186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 05:57:59  来源:igfitidea点击:

How to calculate Rolling Correlation with pandas?

pythonpandasdataframecorrelation

提问by Arthur Coimbra

I understand how to calculate a rolling sum, std or average. Example:

我了解如何计算滚动总和、标准或平均值。例子:

df['MA10'] = df['Asset1'].rolling(10).mean()

But I don't understand the syntax to calculate the rolling correlation between two dataframes columns: df['Asset1']and df['Asset2']

但我不明白计算两个数据框列之间滚动相关性的语法:df['Asset1']df['Asset2']

The documentation doesn't provide any example regarding the correlation.

该文档没有提供有关相关性的任何示例。

https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.rolling.html

https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.rolling.html

Any insights?

任何见解?

Thanks!

谢谢!

回答by chrisaycock

It's in there, even if hidden a bit:

它就在那里,即使有点隐藏:

df['Asset1'].rolling(10).corr(df['Asset2'])