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

前端 未结 7 1375
无人及你
无人及你 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:43

    We can easily do it by using groupby and count. But, we should remember to use reset_index().

    df[['col1','col2','col3','col4']].groupby(['col1','col2']).count().\
    reset_index()
    

提交回复
热议问题