def get_most_abundant_pert_ids(dataset, k):
    """ Returns the k most abundant perturbagen ids for each pert-type in dataset."""
    subset = (
        dataset.sample_meta.groupby(["pert_type", "pert_id"])
        .size()
        .sort_values()
        .to_frame()
        .groupby("pert_type")
        .tail(k)
        .reset_index()
    )
    return subset.pert_id.values