You can chain it with df.max which takes level as parameter. At level 0 it takes max from every Customer_ID.

df.groupby(["Customer_ID", "Col2_ID"]).Qta.sum().max(level=0)

Here, you will index as Customer_ID only to get both Customer_id and Col2_ID as index try this.

out = df.groupby(["Customer_ID", "Col2_ID"]).Qta.sum().reset_index(level=1)
idx = out['Qta'].max(level=0).index
out.loc[idx].set_index('Col2_ID', append=True)

Now, here index of out is MultiIndex with Customer_ID and Col2_ID

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top