def create_equal_sized_groups(input_df, ordered_gb, agg_col='qty',
    min_grp_size=1000000.0):
    """Create most granular groups possible s.t. each group has a total <agg_col> of min_size
    Args:
        input_df: df to make groupings from
        ordered_gb: (iterable, sorted granular -> coarse) will try to make a group at [0], then [1],
            until has passed through whole list
        agg_col: (str) col used to decide how big a group is
        min_grp_size: (numeric) minimum size for a group

    Returns:
        result_df: (pd.DataFrame) with ordered_gb columns replaced with Other for too small groups
    """
    result_df = input_df.copy()
    for i in range(1, len(ordered_gb) + 1):
        gb = ordered_gb[:i]
        group_totals = result_df.groupby(gb)[agg_col].sum()
        sum_over_grps = group_totals.to_frame('group_total').reset_index()
        result_df = result_df.merge(sum_over_grps, how='left')
        result_df.loc[result_df['group_total'] < min_grp_size, gb] = 'Other'
        result_df = result_df.drop(['group_total'], 1)
    return result_df
