def process_header()

in sig-contributor-experience/surveys/k8s_survey_analysis/prepare_2019.py [0:0]


def process_header(df):
    columns = list(df.columns)
    new_columns = [None]*len(columns)
    for i, col in enumerate(columns):
        if col[1].startswith("Unnamed") or col[1] == "Response":
            new_columns[i] = col[0]
            continue

        # Find the starting column for the multilabel responses (checkboxes)
        # that were also in the 2018 survey
        if col[0] == blockers_header:
            blockers_i = i
        elif col[0] == contribute_header:
            contribute_i = i
        elif col[0] == news_header:
            news_i = i
        elif col[0] == use_freq_header:
            use_freq_i = i
        elif col[0] == most_important_proj_header:
            most_important_proj_i = i
        elif col[0] == agree_header: # Starting columns for multilabel responses that weren't in the 2018 survey.
            agree_i = i
        elif col[0] == attend_header:
            attend_i = i
        #elif col[0] == unattendance_header:
        #    unattendance_i = i
        else: # Handle open ended responses
            new_columns[i] = col[0]

    def prefix_cols(header, header_i, prefix):
        i = header_i
        while i < len(columns) and (columns[i][0].startswith("Unnamed") or columns[i][0] == header):
            new_columns[i] = "{} {}".format(prefix, columns[i][1])
            i += 1

    prefix_cols(contribute_header, contribute_i, "Contribute:")
    prefix_cols(blockers_header, blockers_i, "Blocker:")
    prefix_cols(news_header, news_i, "Check for news:")
    prefix_cols(use_freq_header, use_freq_i, "Use freq:")
    prefix_cols(most_important_proj_header, most_important_proj_i, "Most Important Project:")

    prefix_cols(agree_header, agree_i, "Agree:")
    prefix_cols(attend_header, attend_i, "Would attend if:")

    df.columns = new_columns