如何在python中将聚合和groupby应用于数据帧?

2024-10-06 08:14:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个名为Dataprep的数据帧,有19列和18484个raw。我已经用下面的代码聚合了我想要的列:

Dataprep.groupby('CustomerKey').OrderQuantity.agg('count')

CustomerKey是客户的ID号,orderquantity是每个客户的订单数。数据看起来像

11000-1个

11000-1个

11000-1个

11000-1个

11001年-1月

11001年-1月

11001年-1月

11001年-1月

11002年-1月

11002年-1月

11002年-1月

11002年-1月

11002年-1月

11003年-1月

11003年-1月

11003年-1月

11003年-1月

11003年-1月

11004年-1月

11004年-1月

11004年-1月

11004年-1月

第一列是customerkey,另一列是orderquantity

我的问题是如何将其应用于DataFrame Dataprep。我想保留所有其他栏目

谢谢


Tags: 数据代码iddataframeraw客户countagg