def order_cols_by_nunique(df, cols):
    """
    Reorder columns in cols according to number of unique values in the df.
    This can be used to have a cleaner grouped (multi-level) x-axis where
    the level with the least unique values is at the bottom.
    Note: alternatively you could remove cols that have only 1 unique value
    :param df: pandas DataFrame
    :param cols: list of columns to reorder
    :return:
    """
    unique_count = df[cols].nunique().sort_values()
    re_ordered_cols = list(unique_count.index.values)
    return re_ordered_cols