You can use the header
, index_col
and tupleize_cols
arguments of read_csv
:
In [1]: df = pd.read_csv('foo.csv', header=[0, 1, 2], index_col=[0, 1], tupleize_cols=False, sep='\s*,\s+')
Note: in 0.13 tupelize=False
will be the default, so you won't need to use that.
There's a little bit of hacking required to get out the column level names:
In [2]: df.columns.names = df.columns[0]
In [3]: del df[df.columns[0]]
In [4]: df
Out[4]:
colLabel:name dog bat Ostrich
colLabel:genus Canis Chiroptera Struthio,
colLabel:activity diurnal nocturnal diurnal
day time of day
Monday morning 17 5 2
day 63 0 34
night 21 68 1
Friday day 72 0 34