def filter_on_n_datasets(counts_in_datasets, min_datasets):
    """ Given a data frame with columns gene_ID, transcript_ID, dataset,
        and count (in that dataset), count the number of datasets that each
        transcript appears in. Then, filter the data such that only transcripts
        found in at least 'min_datasets' remain. """
    
    cols = ['gene_ID', 'transcript_ID']
    dataset_count_df = counts_in_datasets[cols].groupby(cols).size()
    dataset_count_df = dataset_count_df.reset_index()
    dataset_count_df.columns = cols + ["n_datasets"]

    filtered = dataset_count_df.loc[dataset_count_df['n_datasets'] >= min_datasets]
    return filtered