<small id='DYU7P'></small><noframes id='DYU7P'>

  1. <tfoot id='DYU7P'></tfoot>
    <i id='DYU7P'><tr id='DYU7P'><dt id='DYU7P'><q id='DYU7P'><span id='DYU7P'><b id='DYU7P'><form id='DYU7P'><ins id='DYU7P'></ins><ul id='DYU7P'></ul><sub id='DYU7P'></sub></form><legend id='DYU7P'></legend><bdo id='DYU7P'><pre id='DYU7P'><center id='DYU7P'></center></pre></bdo></b><th id='DYU7P'></th></span></q></dt></tr></i><div id='DYU7P'><tfoot id='DYU7P'></tfoot><dl id='DYU7P'><fieldset id='DYU7P'></fieldset></dl></div>
    <legend id='DYU7P'><style id='DYU7P'><dir id='DYU7P'><q id='DYU7P'></q></dir></style></legend>

      • <bdo id='DYU7P'></bdo><ul id='DYU7P'></ul>

    1. 用Pandas.Rolling计算滚动自相关

      Computing Rolling autocorrelation using Pandas.rolling(用Pandas.Rolling计算滚动自相关)

      <tfoot id='JrOr5'></tfoot>

      <small id='JrOr5'></small><noframes id='JrOr5'>

      1. <legend id='JrOr5'><style id='JrOr5'><dir id='JrOr5'><q id='JrOr5'></q></dir></style></legend>
              <tbody id='JrOr5'></tbody>
            <i id='JrOr5'><tr id='JrOr5'><dt id='JrOr5'><q id='JrOr5'><span id='JrOr5'><b id='JrOr5'><form id='JrOr5'><ins id='JrOr5'></ins><ul id='JrOr5'></ul><sub id='JrOr5'></sub></form><legend id='JrOr5'></legend><bdo id='JrOr5'><pre id='JrOr5'><center id='JrOr5'></center></pre></bdo></b><th id='JrOr5'></th></span></q></dt></tr></i><div id='JrOr5'><tfoot id='JrOr5'></tfoot><dl id='JrOr5'><fieldset id='JrOr5'></fieldset></dl></div>

              • <bdo id='JrOr5'></bdo><ul id='JrOr5'></ul>
                本文介绍了用Pandas.Rolling计算滚动自相关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试使用Pandas(0.23.3)计算Series对象的滚动自相关

                设置示例:

                dt_index = pd.date_range('2018-01-01','2018-02-01', freq = 'B')
                data = np.random.rand(len(dt_index))
                s = pd.Series(data, index = dt_index)
                

                创建窗口大小为5的Rolling对象:

                r = s.rolling(5)
                

                获取:

                Rolling [window=5,center=False,axis=0]
                

                现在,当我尝试计算相关性时(我很肯定这是错误的方法):

                r.corr(other=r)
                

                我只收到nans

                我尝试了另一种基于documentation::

                的方法
                df = pd.DataFrame()
                df['a'] = s
                df['b'] = s.shift(-1)
                df.rolling(window=5).corr()
                

                获得如下内容:

                ...
                2018-03-01 a NaN NaN
                           b NaN NaN
                

                我真的不确定我在哪里出错了。任何帮助都将不胜感激!文档也使用了float64。认为这是因为相关性非常接近于零,所以显示为NaN?有人提出了错误报告here,但我认为Jreback在以前的错误修复中解决了问题。

                这是另一个相关答案,但它使用的是似乎在Pandas版本0.23.3中不受支持的pd.rolling_apply?

                推荐答案

                IIUC,

                >>> s.rolling(5).apply(lambda x: x.autocorr(), raw=False)
                
                2018-01-01         NaN
                2018-01-02         NaN
                2018-01-03         NaN
                2018-01-04         NaN
                2018-01-05   -0.502455
                2018-01-08   -0.072132
                2018-01-09   -0.216756
                2018-01-10   -0.090358
                2018-01-11   -0.928272
                2018-01-12   -0.754725
                2018-01-15   -0.822256
                2018-01-16   -0.941788
                2018-01-17   -0.765803
                2018-01-18   -0.680472
                2018-01-19   -0.902443
                2018-01-22   -0.796185
                2018-01-23   -0.691141
                2018-01-24   -0.427208
                2018-01-25    0.176668
                2018-01-26    0.016166
                2018-01-29   -0.876047
                2018-01-30   -0.905765
                2018-01-31   -0.859755
                2018-02-01   -0.795077
                

                这篇关于用Pandas.Rolling计算滚动自相关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                Is there a way of group by month in Pandas starting at specific day number?( pandas 有从特定日期开始的按月分组的方式吗?)
                Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)

                <small id='smG2u'></small><noframes id='smG2u'>

                      <i id='smG2u'><tr id='smG2u'><dt id='smG2u'><q id='smG2u'><span id='smG2u'><b id='smG2u'><form id='smG2u'><ins id='smG2u'></ins><ul id='smG2u'></ul><sub id='smG2u'></sub></form><legend id='smG2u'></legend><bdo id='smG2u'><pre id='smG2u'><center id='smG2u'></center></pre></bdo></b><th id='smG2u'></th></span></q></dt></tr></i><div id='smG2u'><tfoot id='smG2u'></tfoot><dl id='smG2u'><fieldset id='smG2u'></fieldset></dl></div>

                        <tbody id='smG2u'></tbody>
                      <tfoot id='smG2u'></tfoot><legend id='smG2u'><style id='smG2u'><dir id='smG2u'><q id='smG2u'></q></dir></style></legend>

                          <bdo id='smG2u'></bdo><ul id='smG2u'></ul>