Specify Multi-Level columns using pd.read_clipboard?

混江龙づ霸主 提交于 2021-01-28 05:02:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!