def dataframe_indexes_to_columns(df):
    """
    Adds index columns as regular columns if necessary. Modifies df.
    """
    for index_index, index_name in enumerate(df.index.names):
        if index_name not in df.columns:
            df[index_name] = df.index.get_level_values(index_name).values
    return df