[英]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.