Python Pandas : group by in group by and average?

前端 未结 2 1812
温柔的废话
温柔的废话 2020-11-22 08:39

I have a dataframe like this:

cluster  org      time
   1      a       8
   1      a       6
   2      h       34
   1      c       23
   2      d       74
          


        
2条回答
  •  广开言路
    2020-11-22 09:26

    I would simply do this, which literally follows what your desired logic was:

    df.groupby(['org']).mean().groupby(['cluster']).mean()
    

提交回复
热议问题