Python Pandas: Is Order Preserved When Using groupby() and agg()?

前端 未结 5 2057
清歌不尽
清歌不尽 2020-12-14 00:21

I\'ve frequented used pandas\' agg() function to run summary statistics on every column of a data.frame. For example, here\'s how you would produce the mean an

5条回答
  •  独厮守ぢ
    2020-12-14 00:42

    Even easier:

      import pandas as pd
      pd.pivot_table(df,index='A',aggfunc=(np.mean))
    

    output:

                B    C
         A                
       group1  11.0  101
       group2  17.5  175
       group3  11.0  101
    

提交回复
热议问题