问题
Here's some data from another question:
main Meas1 Meas2 Meas3 Meas4 Meas5
sublvl Value Value Value Value Value
count 7.000000 1.0 1.0 582.00 97.000000
mean 30 37.0 26.0 33.03 16.635350
I would like to read in this data in such a way that the first column is actually the index, and the first two rows are treated as multi-level columns where MeasX is the first level, and Value is the second level.
How can I do this using pd.read_clipboard?
My pd.read_clipboard series:
How do you handle column names having spaces in them when using pd.read_clipboard?
How to handle custom named index when copying a dataframe using pd.read_clipboard?
Copying MultiIndex dataframes with pd.read_clipboard?
回答1:
In [17]: pd.read_clipboard(sep='\s+', index_col=[0], header=[0,1])
Out[17]:
main Meas1 Meas2 Meas3 Meas4 Meas5
sublvl Value Value Value Value Value
count 7.0 1.0 1.0 582.00 97.00000
mean 30.0 37.0 26.0 33.03 16.63535
来源:https://stackoverflow.com/questions/45800520/specify-multi-level-columns-using-pd-read-clipboard