Pandas 带最小值、最大值和总和的数据框分组

Pandas dataframe Groupby with Min,Max and Sum

我在 AID 级别有以下数据框,我想 Group By 在具有 min 优先级的 CID 上,max Ind 值并计算 sum金额字段

数据框

AID   CID   priority amount    Ind
100   C100     1       50       1
200   C100     2       100      0
300   C300     5       300      0
400   C300     3       200      0
500   C300     4       150      0

所需的数据帧

CID  Priority   amount   Ind
C100    1       150       1
C300    3       650       0

我试过了

df2=df.groupby(['CID']).min('Priority')

Error: method object is not subscriptable
print(
    df.groupby("CID", as_index=False).agg(
        {"priority": "min", "Ind": "max", "amount": "sum"}
    )
)

打印:

    CID  priority  Ind  amount
0  C100         1    1     150
1  C300         3    0     650