Home > Enterprise >  Split and merge 2 columns pandas
Split and merge 2 columns pandas

Time:01-06

Is it possible to have this kind of disposition in pd.DataFrame : enter image description here

CodePudding user response:

Create DataFrame by constructor with enter image description here

import pandas as pd

dt = pd.read_excel("1.xlsx", header=[0,1])
print(dt.head())
print(dt.columns)

output:

                  id   male    
  Unnamed: 0_level_1   name age
0                  1   mary  19
1                  2  emily  20
MultiIndex([(  'id', 'Unnamed: 0_level_1'),
            ('male',               'name'),
            ('male',                'age')],
           )
  • Related