def get_average_reward_by(customers, offer, by_col):
    """ Get the average reward received by customers that completed
    the offer, grouped by a column
    Input:
    - customers: dataframe with aggregated data of the offers
    - offer: offer of interest
    - by_col: column used to group the data
    Output:
    - reward: average reward
    """
    cpd_col = '{}_completed'.format(offer)
    rwd_col = '{}_reward'.format(offer)
    completed = customers[(customers.valid == 1) &
                          (customers[cpd_col] > 0)].groupby(by_col)

    return completed[rwd_col].sum() / completed[cpd_col].count()