What is the difference between sum() and count() in pandas?

后端 未结 3 1451
天涯浪人
天涯浪人 2020-12-12 00:44

Can you help me understand the difference between the statements mentioned below? Given that Survived column contains binary data (0,1), they give different ans

3条回答
  •  独厮守ぢ
    2020-12-12 01:26

    count() It's a string function, which count the total number of individual category. And that's the reason we put this in quotes while using it in aggregate function.

    Ex

    grouped = order_products_all.groupby("product_id")["reordered"].aggregate(
        {'reorder_sum': sum,'reorder_total': 'count'}
    ).reset_index()
    

    sum() It's a integer function, which sum the number of unique category.

提交回复
热议问题