Pandas function operations

Here is the answer that worked for me:

def answer_five():
    return census_df.groupby(["STNAME"],sort=False).sum()["COUNTY"].idxmax()

First part created aggregated df

census_df.groupby(["STNAME"],sort=False).sum()

Second part takes the col you need

["COUNTY"].idxmax()

and returns value corresponding to index with max, check here

Leave a Comment