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

    <tfoot id='q2Cfm'></tfoot>
  • <legend id='q2Cfm'><style id='q2Cfm'><dir id='q2Cfm'><q id='q2Cfm'></q></dir></style></legend>
      <bdo id='q2Cfm'></bdo><ul id='q2Cfm'></ul>

        <i id='q2Cfm'><tr id='q2Cfm'><dt id='q2Cfm'><q id='q2Cfm'><span id='q2Cfm'><b id='q2Cfm'><form id='q2Cfm'><ins id='q2Cfm'></ins><ul id='q2Cfm'></ul><sub id='q2Cfm'></sub></form><legend id='q2Cfm'></legend><bdo id='q2Cfm'><pre id='q2Cfm'><center id='q2Cfm'></center></pre></bdo></b><th id='q2Cfm'></th></span></q></dt></tr></i><div id='q2Cfm'><tfoot id='q2Cfm'></tfoot><dl id='q2Cfm'><fieldset id='q2Cfm'></fieldset></dl></div>
      1. 移动平均线 pandas

        Moving Average Pandas(移动平均线 pandas )
        • <legend id='elsOH'><style id='elsOH'><dir id='elsOH'><q id='elsOH'></q></dir></style></legend>
              <bdo id='elsOH'></bdo><ul id='elsOH'></ul>

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

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

              • <tfoot id='elsOH'></tfoot>
                  <tbody id='elsOH'></tbody>

                1. 本文介绍了移动平均线 pandas 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在我的交易时间序列中添加移动平均计算.

                  I would like to add a moving average calculation to my exchange time series.

                  来自 Quandl

                  Exchange = Quandl.get("BUNDESBANK/BBEX3_D_SEK_USD_CA_AC_000",
                                        authtoken="xxxxxxx")
                  
                  #               Value
                  # Date               
                  # 1989-01-02  6.10500
                  # 1989-01-03  6.07500
                  # 1989-01-04  6.10750
                  # 1989-01-05  6.15250
                  # 1989-01-09  6.25500
                  # 1989-01-10  6.24250
                  # 1989-01-11  6.26250
                  # 1989-01-12  6.23250
                  # 1989-01-13  6.27750
                  # 1989-01-16  6.31250
                  
                  # Calculating Moving Avarage
                  MovingAverage = pd.rolling_mean(Exchange,5)
                  
                  #               Value
                  # Date          
                  # 1989-01-02      NaN
                  # 1989-01-03      NaN
                  # 1989-01-04      NaN
                  # 1989-01-05      NaN
                  # 1989-01-09  6.13900
                  # 1989-01-10  6.16650
                  # 1989-01-11  6.20400
                  # 1989-01-12  6.22900
                  # 1989-01-13  6.25400
                  # 1989-01-16  6.26550
                  

                  我想使用相同的索引 (Date) 在 Value 之后将计算出的移动平均线作为一个新列添加到右侧.最好我还想将计算出的移动平均线重命名为 MA.

                  I would like to add the calculated Moving Average as a new column to the right after Value using the same index (Date). Preferably I would also like to rename the calculated moving average to MA.

                  推荐答案

                  滚动平均值返回一个 Series 您只需将其添加为 DataFrame 的新列(MA) 如下所述.

                  The rolling mean returns a Series you only have to add it as a new column of your DataFrame (MA) as described below.

                  有关信息,rolling_mean 函数已在 pandas 较新版本中被弃用.我在示例中使用了新方法,请参阅下面来自 pandas 文档.

                  For information, the rolling_mean function has been deprecated in pandas newer versions. I have used the new method in my example, see below a quote from the pandas documentation.

                  警告 0.18.0 之前的版本、pd.rolling_*pd.expanding_*pd.ewm* 是模块级函数,现在已弃用.这些通过使用 RollingExpandingEWM. 对象以及相应的方法调用来替换.

                  Warning Prior to version 0.18.0, pd.rolling_*, pd.expanding_*, and pd.ewm* were module level functions and are now deprecated. These are replaced by using the Rolling, Expanding and EWM. objects and a corresponding method call.

                  df['MA'] = df.rolling(window=5).mean()
                  
                  print(df)
                  #             Value    MA
                  # Date                   
                  # 1989-01-02   6.11   NaN
                  # 1989-01-03   6.08   NaN
                  # 1989-01-04   6.11   NaN
                  # 1989-01-05   6.15   NaN
                  # 1989-01-09   6.25  6.14
                  # 1989-01-10   6.24  6.17
                  # 1989-01-11   6.26  6.20
                  # 1989-01-12   6.23  6.23
                  # 1989-01-13   6.28  6.25
                  # 1989-01-16   6.31  6.27
                  

                  这篇关于移动平均线 pandas 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Split a Pandas column of lists into multiple columns(将 Pandas 的列表列拆分为多列)
                  How does the @property decorator work in Python?(@property 装饰器在 Python 中是如何工作的?)
                  What is the difference between old style and new style classes in Python?(Python中的旧样式类和新样式类有什么区别?)
                  How to break out of multiple loops?(如何打破多个循环?)
                  How to put the legend out of the plot(如何将传说从情节中剔除)
                  Why is the output of my function printing out quot;Nonequot;?(为什么我的函数输出打印出“无?)
                      <bdo id='MS7fW'></bdo><ul id='MS7fW'></ul>
                      <legend id='MS7fW'><style id='MS7fW'><dir id='MS7fW'><q id='MS7fW'></q></dir></style></legend>
                          <tbody id='MS7fW'></tbody>

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

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

                            <tfoot id='MS7fW'></tfoot>