in [ ]df boys[boys year = in [ ]in df sort_index(by='prop'ascending=falseprop cumsum(in [ ]in searchsorted( out[ ] it should now be fairly straightforward to apply this operation to each year/sex combinationgroupby those fields and apply function returning the count for each groupdef get_quantile_count(groupq= )group group sort_index(by='prop'ascending=falsereturn group prop cumsum(searchsorted( diversity top groupby(['year''sex']apply(get_quantile_countdiversity diversity unstack('sex'this resulting dataframe diversity now has two time seriesone for each sexindexed by year this can be inspected in ipython and plotted as before (see figure - )in [ ]diversity head(out[ ]sex year in [ ]diversity plot(title="number of popular names in top %"figure - plot of diversity metric by year us baby names - www it-ebooks info