<legend id='vBHaq'><style id='vBHaq'><dir id='vBHaq'><q id='vBHaq'></q></dir></style></legend>
  • <tfoot id='vBHaq'></tfoot>

  • <small id='vBHaq'></small><noframes id='vBHaq'>

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

        为什么Groupby和Rolling不能一起工作?

        Why is groupby and rolling not working together?(为什么Groupby和Rolling不能一起工作?)

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

          <tbody id='ivtYw'></tbody>
          <bdo id='ivtYw'></bdo><ul id='ivtYw'></ul>

          • <legend id='ivtYw'><style id='ivtYw'><dir id='ivtYw'><q id='ivtYw'></q></dir></style></legend>

              • <tfoot id='ivtYw'></tfoot>

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

                  本文介绍了为什么Groupby和Rolling不能一起工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个从CoinMarketcap上刮来的DF。我正在尝试计算CLOSE_PRICE列的卷度量,但在使用GROUPBY时收到错误消息:

                  final_coin_data['vol'] = final_coin_data.groupby('coin_name')['close_price'].rolling(window=30).std()
                  TypeError: incompatible index of inserted column with frame index
                  

                  df结构(‘unname:0’是在我加载CSV之后出现的):

                      Unnamed: 0  close_price coin_name   date            high_price  low_price    market_cap         open_price  volume
                  0   1           9578.63     Bitcoin     Mar 11, 2018    9711.89     8607.12      149,716,000,000    8852.78     6,296,370,000
                  1   2           8866.00     Bitcoin     Mar 10, 2018    9531.32     8828.47      158,119,000,000    9350.59     5,386,320,000
                  2   3           9337.55     Bitcoin     Mar 09, 2018    9466.35     8513.03      159,185,000,000    9414.69     8,704,190,000
                  3   1           9578.63     Monero      Mar 11, 2018    9711.89     8607.12      149,716,000,000    8852.78     6,296,370,000
                  4   2           8866.00     Monero      Mar 10, 2018    9531.32     8828.47      158,119,000,000    9350.59     5,386,320,000
                  5   3           9337.55     Monero      Mar 09, 2018    9466.35     8513.03      159,185,000,000    9414.69     8,704,190,000
                  

                  (忽略不正确的价格,这是DF的基础)

                  使用以下代码时:

                  final_coin_data1['vol'] = final_coin_data.groupby('coin_name')['close_price'].rolling(window=30).std().reset_index(0,drop=True)
                  

                  我遇到内存错误。我以为我用团购是正确的。如果我取出final_coin_data1['vol'] =,那么我会得到一个看起来正确的序列,但它不会让我重新插入到DF中。

                  当我第一次开始这个项目时。我只有一枚硬币,使用下面的代码,它计算波动率没有问题。

                   final_coin_data1['vol'] = final_coin_data['close_price'].rolling(window=30).std()
                  

                  推荐答案

                  当我运行此程序时,

                  final_coin_data['close_price'].rolling(window=30).std()
                  
                  将生成索引列和结果列。当我尝试将其合并回原始DF作为新列final_coin_data1['vol']时,收到错误TypeError: incompatible index of inserted column with frame index,因此要更正此错误,我reset_index(drop=True)随后删除了允许在final_coin_data1['vol']上联接结果的索引。

                  最终功能代码如下所示:

                  final_coin_data1['vol'] = final_coin_data.groupby('coin_name')['close_price'].rolling(window=30).std().reset_index(0,drop=True)
                  

                  这篇关于为什么Groupby和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='49ohY'></small><noframes id='49ohY'>

                    <tfoot id='49ohY'></tfoot>
                    <legend id='49ohY'><style id='49ohY'><dir id='49ohY'><q id='49ohY'></q></dir></style></legend>
                          <bdo id='49ohY'></bdo><ul id='49ohY'></ul>

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