如何计算与 pandas 的滚动相关性? [英] How to calculate Rolling Correlation with pandas?
本文介绍了如何计算与 pandas 的滚动相关性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我了解如何计算滚动总和,std或平均值.示例:
I understand how to calculate a rolling sum, std or average. Example:
df['MA10'] = df['Asset1'].rolling(10).mean()
但是我不理解用于计算两个数据框列之间滚动相关性的语法:df['Asset1']
和df['Asset2']
But I don't understand the syntax to calculate the rolling correlation between two dataframes columns: df['Asset1']
and df['Asset2']
文档中没有提供有关关联的任何示例.
The documentation doesn't provide any example regarding the correlation.
https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.rolling.html
有什么见解吗?
谢谢!
推荐答案
即使隐藏了一点,它也在那里:
It's in there, even if hidden a bit:
df['Asset1'].rolling(10).corr(df['Asset2'])
这篇关于如何计算与 pandas 的滚动相关性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文