def sort_questions(data_df, grouped_questions, grouped_choices, sort_by_choices):
    """
    Sort questions in the dataframe to plot them in their group and sort them in their group according to the responses.
    Args:
        data_df (df): Dataframe of data to plot
        grouped_questions (list): each sub-list is a group of questions which will be plotted together
        grouped_choices (dict): choices sorted by location where they will be plotted ("left", "center", "right")
        sort_by_choices (str): choices by which to sort the questions ("left", "right", "no_sorting")

    Returns:
        df: Dataframe with reordered columns (columns represent the questions)
    """
    if sort_by_choices == "no_sorting":
        return data_df
    # sort questions by the selected sorting (left / right)
    # and add half of the "centered" responses as well since they shift the bars outside as well
    sorted_questions = (
        (
            data_df.loc[grouped_choices[sort_by_choices]].sum(axis=0)
            + data_df.loc[grouped_choices["center"]].sum(axis=0) / 2
        )
        .sort_values(ascending=False)
        .index
    )
    # resort data frame according to the groups so the questions are sorted within each group by the selected sorting
    sorted_group_questions = [
        question
        for question_group in grouped_questions
        for question in sorted_questions
        if question in question_group
    ]
    return data_df.reindex(columns=sorted_group_questions)