简体   繁体   English

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

[英]Python pandas to read an Excel file with more than one row headers

Like the data here, if I have more than one header, how can we read the specific column that I want, thanks!像这里的数据一样,如果我有多个header,我们怎么能读到我想要的具体列,谢谢!

       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    

You have to use the xs function: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.xs.html You have to use the xs function: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.xs.html

For exemple举个例子

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

Or或者

print(df.xs('#1', level='number', axis=1)) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在每个单元格中具有一排以​​上的列的大熊猫中读取Excel文件 - How to read excel file in pandas with a column with more than one rows within each cell 合并具有超过 1 行标题的多个 Excel 文件 - Merging Multiple Excel files with more than 1 row of headers Python:当列标题中包含特殊字符时,使用Pandas读取Excel文件 - Python: read an Excel file using Pandas when the file has special characters in column headers Python循环遍历excel文件并使用pandas read_excel函数一一读取 - Python Loop through excel file and and read each one by one using pandas read_excel function 如何使用pandas read_csv()读取一个文件,其中包含多个表? - How to use pandas read_csv() to read a file containing more than just one table? Python:具有多个条件的熊猫总和 - Python : Pandas Sum with more than one condition 在Python CSV中跳过多行 - Skipping more than one row in Python csv python pandas标志是否每个列中的每个值都有一个以上的唯一行 - python pandas flag if more than one unique row per value in column Pandas Python:read_excel:是否可以只读取特定数据类型的列标题(将标题读取为字符串)? - Pandas Python: read_excel: Is it possible to only read the column headers in a certain data type (read the headers as strings)? 读取文件的多行 - Read more than one line of a file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM