def select_last_n_imports(stats_file, n=3):
    """
    Selects which independent full and partial imports should be plotted based on n.

    :param stats_file: pandas DataFrame with stats data.
    :param int n: number of independent imports to select.
    :return: List of import ids to be plotted according to selection criterion.
    """
    partial = []
    full = []
    if 'datetime' in  stats_file and 'import_id' in stats_file and 'Import_flag' in stats_file:
        df = stats_file[['datetime', 'import_id', 'Import_flag']].sort_values('datetime', ascending=False).drop_duplicates(['import_id'], keep = 'first', inplace = False)
        full = df[df['Import_flag'] == 'full']
        full = full.iloc[:n, 1].tolist()
        partial = df[df['Import_flag'] == 'partial']
        partial = partial.iloc[:n, 1].tolist()
    
    return partial + full