Python熊猫读取具有多个行标题的Excel文件

时间:2020-04-23 19:51:25

标签: python pandas

就像这里的数据一样,如果我有多个标题,我们如何才能读取想要的特定列,谢谢!

       machine A       A       B
       date    12-01  12-02   12-01
       number  #1      #2      #2
              0.223   0.224   0.226
              0.333   0.444   0.234
              0.234   0.124   0.456    

1 个答案:

答案 0 :(得分:1)

您必须使用xs函数: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.xs.html

例如

print(df.xs('A', level='machine', axis=1)) 

print(df.xs('#1', level='number', axis=1)) 
相关问题