def transform_ses_order(df, ses_column_name):
    """
    Orders the ses_column_name level by ses_level if given in data frame
    Args:
        df: demographic data
        ses_column_name: the column name in the demographic data that describes socio-economic status
    Returns: Dataframe sorted by ses level.
    """
    if "ses_level" not in df.columns.values:
        return df

    # ordering the levels by ses_level:
    level_order = sorted(set(zip(df.ses_level, df[ses_column_name])))
    level_order = [lev[1] for lev in level_order]
    df[ses_column_name] = df[ses_column_name].astype("category")
    df[ses_column_name].cat.reorder_categories(level_order, inplace=True)

    return df