def pre_process_avg_values(df, column_name_mappings, is_negative_class=False):
    """
    Input:        Pandas dataframe
    Output:       Pandas dataframe
    Description:  Group all average columns values from chart data on a unique identifying key.

    			  1. Drop rows with null values.
                  2. Pivot the dataframe on an identifying column. Pivot column is 'encounter_id' 
                     for patients without an RRT event (is_negative_class=True) or pivot column 
                     is 'rrt_ce_id' for patients with an RRT event (is_negative_class=False).
                  3. Map the cerner event codes to human readable columns (see column mappings at the top of the file).    
    """


    # Filter out null valued columns
    avg_values = df[df.avg_result.notnull()]
    # Pivot on the RRT event id such that the columns are the event codes and 
    # the values are the numeric values
    if is_negative_class:
        pivot_index = 'encntr_id'
    else:
        pivot_index = 'rrt_ce_id'
    df_return = avg_values.pivot_table(values='avg_result', 
                                        index=pivot_index,
                                       columns='event_cd')
    # Change the column names from event codes to human readable names
    df_return.columns = [column_name_mappings[col] for col in df_return.columns]
    return df_return