【发布时间】:2021-07-16 12:01:02
【问题描述】:
谁能帮我从 ONE pdf 文件中提取多个表格。我有 5 页,每页都有一个表,表头列 exp 相同:
每页的表格exp
student Score Rang
Alex 50 23
Julia 80 12
Mariana 94 4
我想在一个数据框中提取所有这些表,首先我做了
df = tabula.read_pdf(file_path,pages='all',multiple_tables=True)
但我得到了一个凌乱的输出,所以我尝试了如下代码行:
[student Score Rang
Alex 50 23
Julia 80 12
Mariana 94 4 ,student Score Rang
Maxim 43 34
Nourah 93 5]
所以我像这样编辑了我的代码 将熊猫导入为 pd 导入表格
file_path = "filePath.pdf"
# read my file
df1 = tabula.read_pdf(file_path,pages=1,multiple_tables=True)
df2 = tabula.read_pdf(file_path,pages=2,multiple_tables=True)
df3 = tabula.read_pdf(file_path,pages=3,multiple_tables=True)
df4 = tabula.read_pdf(file_path,pages=3,multiple_tables=True)
df5 = tabula.read_pdf(file_path,pages=5,multiple_tables=True)
它为每个表提供了一个数据框,但我不知道如何将其重新组合成一个数据框和任何其他解决方案以避免重复代码行。
【问题讨论】:
标签: python pandas dataframe pdf tabula