使用xlwings读取Excel表标题 [英] Read Excel Table headers with xlwings

查看:895
本文介绍了使用xlwings读取Excel表标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用xlwings将excel中的表"读入pandas DataFrame中,其中表"headers"成为DataFrame列名?

How can I use xlwings to read a "table" in excel, into a pandas DataFrame, where the table "headers" become the DataFrame column names?

我尝试以任何方式读取表,但始终从读取中排除标题行!

Every way I have tried to read the table, the header row is always excluded from the read!

这是我尝试过的内容,其中"b"是我的xlwings工作簿对象:

Here is what I've tried, where "b" is my xlwings workbook object:

b.sheets['Sheet1'].range('Table1').options(pd.DataFrame)
b.sheets['Sheet1'].range('Table1').options(pd.DataFrame, headers=False)
b.sheets['Sheet1'].range('Table1').options(pd.DataFrame, headers=True)

推荐答案

希望这不是 best 的答案,但是我确实发现我可以引用命名范围,然后引用.offset(-1).expand('vertical')

Hoping this is not the best answer, but I did find I could reference the named range, then .offset(-1).expand('vertical')

这篇关于使用xlwings读取Excel表标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆