I have multi-level columns in a csv. How can I read them, while maintaining their multi-level hierarchy?
The contents of the csv are as follows:
name,code,code,date,date,approved
,min,max,min,max,
apple,4,7,20200115,20200724,yes
banana,2,8,20191106,20200809,no
carrot,5,6,20200323,20200617,yes
...
I would like to read them (preferably via pandas) such that the contents of the dataframe are as follows:
name code date approved
min max min max
--- --- --- --- --- ---
apple 4 7 20200115 20200724 yes
banana 2 8 20191106 20200809 no
carrot 5 6 20200323 20200617 yes
...
I have tried the following:
import pandas as pd
df = pd.read_csv(filename, index_col=None)
The above code stores the following contents in df:
name code code.1 date date.1 approved
--- --- --- --- --- ---
0 NaN min max min max NaN
1 apple 4 7 20200115 20200724 yes
2 banana 2 8 20191106 20200809 no
3 carrot 5 6 20200323 20200617 yes
...
which is not what I want. How can I store the contents in the dataframe as described above?