import random


def create_random_subset(data_frame, column_name):
    """Choose a random subset from a DataFrame.

    The column name determines which groups are sampled. Only one image from
    each group is returned.

    :param df: DataFrame of multiple images to sample from.
    :param column_name: column defining the group an image belongs to.
    :returns: DataFrame -- DataFrame with one image from each group.
    """
    def _select_random(x):
        return x.ix[random.sample(x.index, 1)]

    group = data_frame.groupby(column_name)
    random_subset = group.apply(_select_random)
    random_subset.drop(column_name, axis=1, inplace=True)
    random_subset.reset_index(drop=True, level=0, inplace=True)
    return random_subset