<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

      Python Dataframe Groupby Mean and STD(Python Dataframe Groupby Mean和Std)

          <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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                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替换为非空值)
                Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)

                  <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>
                      <tbody id='m4DvF'></tbody>
                    <tfoot id='m4DvF'></tfoot>
                  • <legend id='m4DvF'><style id='m4DvF'><dir id='m4DvF'><q id='m4DvF'></q></dir></style></legend>