Get statistics for each group (such as count, mean, etc) using pandas GroupBy?

前端 未结 7 1563
无人及你
无人及你 2020-11-21 06:06

I have a data frame df and I use several columns from it to groupby:

df[\'col1\',\'col2\',\'col3\',\'col4\'].groupby([\'col1\',\'co         


        
7条回答
  •  天命终不由人
    2020-11-21 06:39

    On groupby object, the agg function can take a list to apply several aggregation methods at once. This should give you the result you need:

    df[['col1', 'col2', 'col3', 'col4']].groupby(['col1', 'col2']).agg(['mean', 'count'])
    

提交回复
热议问题