'How to merge headers with same name into one single header?

I'm going to add MultiIndex column to my dataframe. What I got:

enter image description here

What would I like to get:

enter image description here

full code:

import pandas as pd
data = pd.DataFrame(columns=[1, 2, 3, 4, 5])

dictionary = {1: 'row1', 2: 'row2', 3: 'row2', 4: 'row2', 5: 'row3'}

dictionary1 = {1: 'row4', 2: 'row5', 3: 'row6', 4: 'row7', 5: 'row3'}
dictionary2 = {1: 5, 2: 4, 3: 3, 4: 2, 5: 1}

data = data.append(dictionary, ignore_index=True)
data = data.append(dictionary1, ignore_index=True)
data = data.append(dictionary2, ignore_index=True)
data = data.append(dictionary2, ignore_index=True)
data = data.append(dictionary2, ignore_index=True)

What I did:

arrays = [['row1', 'row2', 'row2', 'row2', 'row3'],
          ['row4', 'row5', 'row6', 'row7', 'row3']]
data.columns = pd.MultiIndex.from_arrays(arrays)

data


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source