在 groupby 中应用 Size() 函数以及聚合参数 - Pandas
Applying Size() function in groupby along with the aggregate parameter - Pandas
我想在使用 groupby 函数和 agg 参数时获取实例数
Name Country X_Id Value
Rahul 1 2 100
Rahul 1 2 50
Matthew 2 3 100
Matthew 1 1 25
Name Country X_Id Value Instances
Rahul 1 2 50 2
Matthew 2 3 100 1
Matthew 1 1 25 1
我用了df.groupby(['SiteId', 'SubUnitId', 'CatId']).agg('mean').size()
但是没用
将 GroupBy.agg
与命名聚合一起使用:
df.groupby(['Name', 'Country', 'X_Id']).agg(Value = ('Value', 'mean'),
Instances = ('Value', 'size'))
我想在使用 groupby 函数和 agg 参数时获取实例数
Name Country X_Id Value
Rahul 1 2 100
Rahul 1 2 50
Matthew 2 3 100
Matthew 1 1 25
Name Country X_Id Value Instances
Rahul 1 2 50 2
Matthew 2 3 100 1
Matthew 1 1 25 1
我用了df.groupby(['SiteId', 'SubUnitId', 'CatId']).agg('mean').size()
但是没用
将 GroupBy.agg
与命名聚合一起使用:
df.groupby(['Name', 'Country', 'X_Id']).agg(Value = ('Value', 'mean'),
Instances = ('Value', 'size'))