在熊猫摘要中创建多列

时间:2019-05-17 03:41:48

标签: python r pandas

在R中,我可以使用多个数据列来汇总数据,如下所示:

`library(dplyr)`
    df %>% 
        group_by(product_id) %>% 
        summarise(
          Total_count = n(),
          Avg_rating = mean(star_rating, na.rm = T),
          Total_product =  round((n() / dim(df)[1]) * 100 ,2) 
    )

但是,我想在大熊猫中进行相同的活动。

1 个答案:

答案 0 :(得分:1)

pandas中,我们有agg

df.groupby('product_id').agg({'product_id':'count','star_rating':'mean'})
相关问题