首页 > 解决方案 > 如何使用 camelot 从 PDF 文件中提取表后获取列名?我是新手

问题描述

简而言之,我正在执行此步骤。

tables = camelot.read_pdf(doc_file)
tables[0].df

tables[0].df.columns用来从提取的表中获取列名。

但它没有给出列名。

标签: python-3.xpython-camelot

解决方案


Camelot 提取的表没有字母列名。

tables[0].df.columns例如,对于三列表返回:

RangeIndex(start=0, stop=3, step=1)

相反,您可以尝试读取第一行并从中获取列表:tables[0].df.iloc[0].tolist(). 输出可能是:

['column1', 'column2', 'column3']

推荐阅读