How do I apply .agg to the top n items in a dataframe


I'm trying to pull back a dataframe object computed from the top 4 items of a larger data set. To do this I've pulled the created a data frame census_df then written the following

return (census_df.set_index('STNAME','COUNTY')
            .nlargest(4,'CENSUS2010POP')
            .groupby(level=0)['CENSUS2010POP']
            .agg([{'Sum':np.sum}]))

which returns the four largest counties rather than all states with their population estimated by the four largest counties inside those states. I tried using

return (census_df.set_index('STNAME','COUNTY')
            .nlargest(4,'CENSUS2010POP')
            .groupby(level=0)['CENSUS2010POP']
            .agg([{'Sum':np.argsort()[-3:].sum()}]))

but argsort is missing a positional argument and I'm not sure what to put there -- what would argsort even reference?



IIUC

census_df.set_index('STNAME','COUNTY').\
      groupby(level=0)['CENSUS2010POP'].\
         agg(lambda x: x.head(4).sum())