Home > Enterprise >  How to have create more than one header in pandas python?
How to have create more than one header in pandas python?

Time:05-26

For the life of me I can't figure out how to use multiindex or any other way to make more than one vertical header for a column. This is the code I have:

import pandas as pd
    
genderad = [['Prescribed Taking', 1458, 4404, 14, 'Prescribed Taking', 1558, 4270, 26], ['Prescribed Not Taking', 226, 781, 1, 'Prescribed Not Taking', 171, 523, 2], ['Not Prescribed', 2302, 6672, 35, 'Not Prescribed', 1899, 4330, 26]]
df = pd.DataFrame(genderad)
df = pd.DataFrame(genderad, columns = ['Medication Status', 'Male', 'Female', 'Z', 'Medication Status', 'Male', 'Female', 'Z'])
df

This code leads me to this table: enter image description here

  • Related