Mar*_*nda 5 python csv pdf pandas
我想处理 PDF 文件,特别是表格。我编码这个
import pandas as pd
import numpy as np
import tabula
from tabula import read_pdf
tab= tabula.read_pdf('..\PDFs\Ala.pdf',encoding='latin-1', pages ='all')
tab
Run Code Online (Sandbox Code Playgroud)
但我得到了一个值列表,如下所示:
[ Nombres Edad Ciudad
0 Noelia 20 Lima
1 Michelie 45 Lima
2 Ximena 18 Lima
3 Miguel 43 Lima]
Run Code Online (Sandbox Code Playgroud)
我无法分析它,因为它不是数据框。这只是一个例子,真实的 PDF 文件包含文本和多个页面之间的表格
那么,请问有人可以帮我解决这个问题吗?
tabula应该返回 Pandas 数据帧列表,每个数据帧对应 PDF 中找到的每个表。您可以按如下方式显示(并使用它们):
import pandas as pd
import numpy as np
import tabula
from tabula import read_pdf
dfs = tabula.read_pdf('..\PDFs\Ala.pdf', encoding='latin-1', pages='all')
print(f"Found {len(dfs)} tables")
# display each of the dataframes
for df in dfs:
print(df.size)
print(df)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6598 次 |
| 最近记录: |