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

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

      <legend id='ilBxs'><style id='ilBxs'><dir id='ilBxs'><q id='ilBxs'></q></dir></style></legend>
        <bdo id='ilBxs'></bdo><ul id='ilBxs'></ul>
    1. Python Dataframe Groupby Mean和Std

      时间:2024-08-21

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

            <tfoot id='NNR1Y'></tfoot>

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

                本文介绍了Python Dataframe Groupby Mean和Std的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我知道如何计算GROUP BY平均值或STD。但现在我想同时计算两者。 我的代码:

                df = 
                   a      b      c      d
                0  Apple  3      5      7
                1  Banana 4      4      8
                2  Cherry 7      1      3
                3  Apple  3      4      7
                
                xdf = df.groupby('a').agg([np.mean(),np.std()])
                

                当前输出:

                TypeError: _mean_dispatcher() missing 1 required positional argument: 'a'
                

                推荐答案

                尝试从np.函数中删除()

                xdf = df.groupby("a").agg([np.mean, np.std])
                print(xdf)
                

                打印:

                          b         c              d     
                       mean  std mean       std mean  std
                a                                        
                Apple     3  0.0  4.5  0.707107    7  0.0
                Banana    4  NaN  4.0       NaN    8  NaN
                Cherry    7  NaN  1.0       NaN    3  NaN
                

                编辑:展平列多索引(&Q;T):

                xdf = df.groupby("a").agg([np.mean, np.std])
                xdf.columns = xdf.columns.map("_".join)
                print(xdf)
                

                打印:

                        b_mean  b_std  c_mean     c_std  d_mean  d_std
                a                                                     
                Apple        3    0.0     4.5  0.707107       7    0.0
                Banana       4    NaN     4.0       NaN       8    NaN
                Cherry       7    NaN     1.0       NaN       3    NaN
                

                这篇关于Python Dataframe Groupby Mean和Std的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:对在多个PANDA列上使用GROUPBY后出现的值进行计数 下一篇:如何使用GROUPBY和应用极点

                相关文章

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

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