Aggregate the data by column - alternative solution

Screen Link:

My Code:

f500['roa'] = f500['profits'] / f500['assets']

top_roa_by_sector2 = f500.groupby('sector').agg({'roa': ['max']})

What I expected to happen:

I tried to aggregate the roa by sector in a different way, with the help of groupby and agg .

The code is working, and it shows the max “roa” of each sector. But i am not able to show the respective “company” with the max “roa” of each sector.

Is this even possible with the methods/functions i am using?

I recently did something along those lines. I believe this is the thread that helped me.

1 Like