<small id='6vSLp'></small><noframes id='6vSLp'>

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

        <bdo id='6vSLp'></bdo><ul id='6vSLp'></ul>

        <legend id='6vSLp'><style id='6vSLp'><dir id='6vSLp'><q id='6vSLp'></q></dir></style></legend><tfoot id='6vSLp'></tfoot>
      1. Dropna设置为True的 pandas Groupby生成错误输出

        Pandas groupby with dropna set to True generating wrong output(Dropna设置为True的 pandas Groupby生成错误输出)

        • <legend id='xbbMY'><style id='xbbMY'><dir id='xbbMY'><q id='xbbMY'></q></dir></style></legend>
            <tbody id='xbbMY'></tbody>

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

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

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

                <tfoot id='xbbMY'></tfoot>
                  本文介绍了Dropna设置为True的 pandas Groupby生成错误输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在以下代码片断中:

                  import pandas as pd
                  import numpy as np
                  
                  df = pd.DataFrame(
                      {
                          "a": [1, 2, 3, 4, 5, 6, 7, 8, 9], 
                          "b": [1, np.nan, 1, np.nan, 2, 1, 2, np.nan, 1]
                      }
                  )
                  df_again = df.groupby("b", dropna=False).apply(lambda x: x)
                  

                  我预期dfdf_again相同。但它们不是:

                  df
                     a    b
                  0  1  1.0
                  1  2  NaN
                  2  3  1.0
                  3  4  NaN
                  4  5  2.0
                  5  6  1.0
                  6  7  2.0
                  7  8  NaN
                  8  9  1.0
                  
                  df_again
                     a    b
                  0  1  1.0
                  2  3  1.0
                  4  5  2.0
                  5  6  1.0
                  6  7  2.0
                  8  9  1.0
                  
                  现在,如果我将lambda表达式略微调整为";,请参阅";What With With by df.groupby("b", dropna=False).apply(lambda x: print(x))我实际上可以想象dfbNaN的那部分也已处理。

                  我这里错过了什么? (使用 pandas 1.3.1和Numpy 1.20.3)

                  推荐答案

                  这是 pandas 1.2.0中引入的错误,如here所述,已解决here。

                  这篇关于Dropna设置为True的 pandas Groupby生成错误输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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替换为非空值)
                1. <i id='guqsW'><tr id='guqsW'><dt id='guqsW'><q id='guqsW'><span id='guqsW'><b id='guqsW'><form id='guqsW'><ins id='guqsW'></ins><ul id='guqsW'></ul><sub id='guqsW'></sub></form><legend id='guqsW'></legend><bdo id='guqsW'><pre id='guqsW'><center id='guqsW'></center></pre></bdo></b><th id='guqsW'></th></span></q></dt></tr></i><div id='guqsW'><tfoot id='guqsW'></tfoot><dl id='guqsW'><fieldset id='guqsW'></fieldset></dl></div>
                            <tbody id='guqsW'></tbody>
                            <bdo id='guqsW'></bdo><ul id='guqsW'></ul>

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

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