Filtering of maximum value by ID and category sum
You could also do the following. Compute the first grouping by id and category, sum up the values:
y = df.groupby([&quot;id&quot;,&quot;category&quot;])[&quot;value&quot;].sum()

Afterwards, grab the best category according to your definition:
y.groupby(&quot;category&quot;).sum().nlargest(1)

Combining these, so that we get the full job done:
y = df.groupby([&quot;id&quot;,&quot;category&quot;])[&quot;value&quot;].sum()
cat = y.groupby(&quot;category&quot;).sum().nlargest(1).index
y.loc[:,cat]