如何使用camelot从PDF文件中提取表格后获取列名?我是新手

问题描述

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

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

我正在使用 tables[0].df.columns提取的表中获取列名。

但它没有给出列名。

解决方法

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

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

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

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

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