I have a dataframe that looks like
column1 column2 column3 colum4 column5
1 r_n_1 r_s_1 r_n_2 r_s_3 r_n_3
2 r_n_1 r_s_1 r_n_4 r_s_4 r_n_5
3 r_n_1 r_s_1 r_n_6 r_s_5 r_n_7
4 r_n_1 r_s_1 r_n_6 r_s_6 r_n_9
5 r_n_10 r_s_7 r_n_11 r_s_8 r_n_12
6 r_n_10 r_s_9 r_n_11 r_s_10 r_n_13
And I would like to merge cells in data frame so I could write in excel that could look like
So basically merge cells that have same value in excel. I am guessing I can use MultiIndex from pandas but I don't know how to do that.
my code to get this data frame is like.
new_list = []
for k1 in remove_empties_from_dict(combined_dict):
curr_dict = remove_empties_from_dict(combined_dict)[k1]
for k2 in curr_dict:
curr_dict_2=curr_dict[k2]
for k3 in curr_dict_2:
curr_dict_3=curr_dict_2[k3]
for k4 in curr_dict_3:
curr_dict_4=curr_dict_3[k4]
new_dict= {'c1': k1, 'c2': k2, 'c3': k3, 'c4': k4,'c5': curr_dict_4}
new_list.append(new_dict)
df = pd.DataFrame(new_list)