If using pandas.read_csv()
or pandas.read_table()
, you can provide a list of indices for the header
argument, to specify the rows you want to use for column headers. Python will generate the pandas.MultiIndex
for you in df.columns
:
df = pandas.read_csv('DollarUnitSales.csv', header=[0,1])
You can also use more than two rows, or non-consecutive rows, to specify the column headers:
df = pandas.read_table('DataSheet1.csv', header=[0,2,3])