returns the max value of a column grouped by another column

PHOTO EMBED

Wed Jun 23 2021 08:03:33 GMT+0000 (Coordinated Universal Time)

Saved by @CaoimhedeFrein #python

max_cust = df.groupby("segment").customers.transform(max)
content_copyCOPY

this code groups the column customers by segment. it then finds the max customer count per segment & makes a new column in the dataframe, populated with that max customer count

https://stackoverflow.com/questions/15705630/get-the-rows-which-have-the-max-value-in-groups-using-groupby